[Python-checkins] CVS: python/dist/src/Lib hmac.py,1.2,1.3

A.M. Kuchling akuchling@users.sourceforge.net
2001年11月02日 13:49:22 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv17429
Modified Files:
	hmac.py 
Log Message:
[Patch #477336] Make hmac.py match PEP247, and fix the copy method() so that 
 it works
Index: hmac.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/hmac.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** hmac.py	2001年09月18日 02:26:39	1.2
--- hmac.py	2001年11月02日 21:49:20	1.3
***************
*** 11,18 ****
 return "".join(map(lambda x, y: chr(ord(x) ^ ord(y)), s1, s2))
 
 class HMAC:
 """RFC2104 HMAC class.
 
! This (mostly) supports the API for Cryptographic Hash Functions (PEP 247).
 """
 
--- 11,22 ----
 return "".join(map(lambda x, y: chr(ord(x) ^ ord(y)), s1, s2))
 
+ # The size of the digests returned by HMAC depends on the underlying
+ # hashing module used.
+ digest_size = None
+ 
 class HMAC:
 """RFC2104 HMAC class.
 
! This supports the API for Cryptographic Hash Functions (PEP 247).
 """
 
***************
*** 28,34 ****
 digestmod = md5
 
 self.outer = digestmod.new()
 self.inner = digestmod.new()
! 
 blocksize = 64
 ipad = "\x36" * blocksize
--- 32,40 ----
 digestmod = md5
 
+ self.digestmod = digestmod
 self.outer = digestmod.new()
 self.inner = digestmod.new()
! self.digest_size = digestmod.digest_size
! 
 blocksize = 64
 ipad = "\x36" * blocksize
***************
*** 57,61 ****
 An update to this copy won't affect the original object.
 """
! return HMAC(self)
 
 def digest(self):
--- 63,71 ----
 An update to this copy won't affect the original object.
 """
! other = HMAC("")
! other.digestmod = self.digestmod
! other.inner = self.inner.copy()
! other.outer = self.outer.copy()
! return other
 
 def digest(self):
***************
*** 89,110 ****
 return HMAC(key, msg, digestmod)
 
- def test():
- def md5test(key, data, digest):
- h = HMAC(key, data)
- assert(h.hexdigest().upper() == digest.upper())
- 
- # Test vectors from the RFC
- md5test(chr(0x0b) * 16,
- "Hi There",
- "9294727A3638BB1C13F48EF8158BFC9D")
- 
- md5test("Jefe",
- "what do ya want for nothing?",
- "750c783e6ab0b503eaa86e310a5db738")
- 
- md5test(chr(0xAA)*16,
- chr(0xDD)*50,
- "56be34521d144c88dbb8c733f0e8b3f6")
- 
- if __name__ == "__main__":
- test()
--- 99,100 ----

AltStyle によって変換されたページ (->オリジナル) /