Debian Codegraph @

lib/Crypto/Random/__init__.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # Random/__init__.py : PyCrypto random number generation
4 #
5 # ===================================================================
6 # The contents of this file are dedicated to the public domain. To
7 # the extent that dedication to the public domain is not available,
8 # everyone is granted a worldwide, perpetual, royalty-free,
9 # non-exclusive license to exercise all rights associated with the
10 # contents of this file for any purpose whatsoever.
11 # No rights are reserved.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
21 # ===================================================================
22
23 __all__ = ['new', 'get_random_bytes']
24
25 from os import urandom
26
27 class _UrandomRNG(object):
28
29 def read(self, n):
30 """Return a random byte string of the desired size."""
31 return urandom(n)
32
33 def flush(self):
34 """Method provided for backward compatibility only."""
35 pass
36
37 def reinit(self):
38 """Method provided for backward compatibility only."""
39 pass
40
41 def close(self):
42 """Method provided for backward compatibility only."""
43 pass
44
45
46 def new(*args, **kwargs):
47 """Return a file-like object that outputs cryptographically random bytes."""
48 return _UrandomRNG()
49
50
51 def atfork():
52 pass
53
54
55 #: Function that returns a random byte string of the desired size.
56 get_random_bytes = urandom
57