Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/google-endpoints/Crypto/Hash/SHA.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # -*- coding: utf-8 -*-
2 #
3 # ===================================================================
4 # The contents of this file are dedicated to the public domain. To
5 # the extent that dedication to the public domain is not available,
6 # everyone is granted a worldwide, perpetual, royalty-free,
7 # non-exclusive license to exercise all rights associated with the
8 # contents of this file for any purpose whatsoever.
9 # No rights are reserved.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 # SOFTWARE.
19 # ===================================================================
20
21 """SHA-1 cryptographic hash algorithm.
22
23 SHA-1_ produces the 160 bit digest of a message.
24
25 >>> from Crypto.Hash import SHA
26 >>>
27 >>> h = SHA.new()
28 >>> h.update(b'Hello')
29 >>> print h.hexdigest()
30
31 *SHA* stands for Secure Hash Algorithm.
32
33 This algorithm is not considered secure. Do not use it for new designs.
34
35 .. _SHA-1: http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
36 """
37
38 _revision__ = "$Id$"
39
40 __all__ = ['new', 'digest_size', 'SHA1Hash' ]
41
42 from Crypto.Util.py3compat import *
43 from Crypto.Hash.hashalgo import HashAlgo
44
45 try:
46 # The sha module is deprecated in Python 2.6, so use hashlib when possible.
47 import hashlib
48 hashFactory = hashlib.sha1
49
50 except ImportError:
51 import sha
52 hashFactory = sha
53
54 class SHA1Hash(HashAlgo):
55 """Class that implements a SHA-1 hash
56
57 :undocumented: block_size
58 """
59
60 #: ASN.1 Object identifier (OID)::
61 #:
62 #: id-sha1 OBJECT IDENTIFIER ::= {
63 #: iso(1) identified-organization(3) oiw(14) secsig(3)
64 #: algorithms(2) 26
65 #: }
66 #:
67 #: This value uniquely identifies the SHA-1 algorithm.
68 oid = b('\x06\x05\x2b\x0e\x03\x02\x1a')
69
70 digest_size = 20
71 block_size = 64
72
73 def __init__(self, data=None):
74 HashAlgo.__init__(self, hashFactory, data)
75
76 def new(self, data=None):
77 return SHA1Hash(data)
78
79 def new(data=None):
80 """Return a fresh instance of the hash object.
81
82 :Parameters:
83 data : byte string
84 The very first chunk of the message to hash.
85 It is equivalent to an early call to `SHA1Hash.update()`.
86 Optional.
87
88 :Return: A `SHA1Hash` object
89 """
90 return SHA1Hash().new(data)
91
92 #: The size of the resulting hash in bytes.
93 digest_size = SHA1Hash.digest_size
94
95 #: The internal block size of the hash algorithm in bytes.
96 block_size = SHA1Hash.block_size
97
98
OLDNEW
« no previous file with comments | « third_party/google-endpoints/Crypto/Hash/RIPEMD.py ('k') | third_party/google-endpoints/Crypto/Hash/SHA224.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698