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

Side by Side Diff: third_party/google-endpoints/Crypto/Hash/MD5.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 """MD5 cryptographic hash algorithm.
22
23 MD5 is specified in RFC1321_ and produces the 128 bit digest of a message.
24
25 >>> from Crypto.Hash import MD5
26 >>>
27 >>> h = MD5.new()
28 >>> h.update(b'Hello')
29 >>> print h.hexdigest()
30
31 MD5 stand for Message Digest version 5, and it was invented by Rivest in 1991.
32
33 This algorithm is insecure. Do not use it for new designs.
34
35 .. _RFC1321: http://tools.ietf.org/html/rfc1321
36 """
37
38 _revision__ = "$Id$"
39
40 __all__ = ['new', 'digest_size', 'MD5Hash' ]
41
42 from Crypto.Util.py3compat import *
43 from Crypto.Hash.hashalgo import HashAlgo
44
45 try:
46 # The md5 module is deprecated in Python 2.6, so use hashlib when possible.
47 import hashlib
48 hashFactory = hashlib.md5
49
50 except ImportError:
51 import md5
52 hashFactory = md5
53
54 class MD5Hash(HashAlgo):
55 """Class that implements an MD5 hash
56
57 :undocumented: block_size
58 """
59
60 #: ASN.1 Object identifier (OID)::
61 #:
62 #: id-md5 OBJECT IDENTIFIER ::= {
63 #: iso(1) member-body(2) us(840) rsadsi(113549)
64 #: digestAlgorithm(2) 5
65 #: }
66 #:
67 #: This value uniquely identifies the MD5 algorithm.
68 oid = b('\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x05')
69
70 digest_size = 16
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 MD5Hash(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 `MD5Hash.update()`.
86 Optional.
87
88 :Return: A `MD5Hash` object
89 """
90 return MD5Hash().new(data)
91
92 #: The size of the resulting hash in bytes.
93 digest_size = MD5Hash.digest_size
94
95 #: The internal block size of the hash algorithm in bytes.
96 block_size = MD5Hash.block_size
97
OLDNEW
« no previous file with comments | « third_party/google-endpoints/Crypto/Hash/MD4.py ('k') | third_party/google-endpoints/Crypto/Hash/RIPEMD.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698