diff options
author | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-02-17 11:21:28 -0800 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-02-17 19:00:50 -0800 |
commit | 59018ff99c97261f9bbaee33f919938871e05118 (patch) | |
tree | a07cdc2d6404d983314e1b5cbae78757e5a7a9be /lib/Crypto/SelfTest | |
parent | 4e4cc0beefbb316db2a8750e747e697df0b754d7 (diff) | |
download | pycrypto-59018ff99c97261f9bbaee33f919938871e05118.tar.gz |
Hash: Remove "oid" attributes; add "name" attribute
In PyCrypto v2.5, the "oid" attribute was added to hash objects. In
retrospect, this was not a good idea, since the OID is not really a
property of the hash algorithm, it's a protocol-specific identifer for
the hash functions. PKCS#1 v1.5 uses it, but other protocols (e.g.
OpenPGP, DNSSEC, SSH, etc.) use different identifiers, and it doesn't make
sense to add these to Crypto.Hash.* every time a new algorithm is added.
This also has the benefit of being compatible with the Python standard
library's "hashlib" objects, which also have a name attribute.
Diffstat (limited to 'lib/Crypto/SelfTest')
-rw-r--r-- | lib/Crypto/SelfTest/Hash/common.py | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/Crypto/SelfTest/Hash/common.py b/lib/Crypto/SelfTest/Hash/common.py index f77fb0f..fa9fd22 100644 --- a/lib/Crypto/SelfTest/Hash/common.py +++ b/lib/Crypto/SelfTest/Hash/common.py @@ -107,16 +107,9 @@ class HashTestOID(unittest.TestCase): self.oid = oid def runTest(self): + from Crypto.Signature import PKCS1_v1_5 h = self.hashmod.new() - if self.oid==None: - try: - raised = 0 - a = h.oid - except AttributeError: - raised = 1 - self.assertEqual(raised,1) - else: - self.assertEqual(h.oid, self.oid) + self.assertEqual(PKCS1_v1_5._HASH_OIDS[h.name], self.oid) class MACSelfTest(unittest.TestCase): @@ -178,11 +171,10 @@ def make_hash_tests(module, module_name, test_data, digest_size, oid=None): description = row[2].encode('latin-1') name = "%s #%d: %s" % (module_name, i+1, description) tests.append(HashSelfTest(module, name, expected, input)) - if oid is not None: - oid = b(oid) name = "%s #%d: digest_size" % (module_name, i+1) tests.append(HashDigestSizeSelfTest(module, name, digest_size)) - tests.append(HashTestOID(module, oid)) + if oid is not None: + tests.append(HashTestOID(module, b(oid))) return tests def make_mac_tests(module, module_name, test_data, hashmods): |