summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLegrandin <gooksankoo@hoiptorrow.mailexpire.com>2011-02-03 01:22:13 +0100
committerLegrandin <gooksankoo@hoiptorrow.mailexpire.com>2011-02-03 01:35:58 +0100
commit3082d19c39ba7208072dd8cc854529b52e0fbbdf (patch)
treeae80654148474cbfc198d7cfa96255a3a2f1381b
parent0d14809acd61782e1e024ca7119b6e4b10dcf7fc (diff)
downloadpycrypto-3082d19c39ba7208072dd8cc854529b52e0fbbdf.tar.gz
Add test routines to validate OID in hash algorithms.
-rw-r--r--lib/Crypto/SelfTest/Hash/common.py16
-rw-r--r--lib/Crypto/SelfTest/Hash/test_MD2.py2
-rw-r--r--lib/Crypto/SelfTest/Hash/test_MD4.py2
-rw-r--r--lib/Crypto/SelfTest/Hash/test_MD5.py2
-rw-r--r--lib/Crypto/SelfTest/Hash/test_RIPEMD.py2
-rw-r--r--lib/Crypto/SelfTest/Hash/test_SHA.py2
-rw-r--r--lib/Crypto/SelfTest/Hash/test_SHA256.py2
7 files changed, 21 insertions, 7 deletions
diff --git a/lib/Crypto/SelfTest/Hash/common.py b/lib/Crypto/SelfTest/Hash/common.py
index d840544..f14c0ce 100644
--- a/lib/Crypto/SelfTest/Hash/common.py
+++ b/lib/Crypto/SelfTest/Hash/common.py
@@ -70,6 +70,19 @@ class HashSelfTest(unittest.TestCase):
self.assertEqual(self.expected, out3) # h = .new(data); h.hexdigest()
self.assertEqual(self.expected, out4) # h = .new(data); h.digest()
+class HashTestOID(unittest.TestCase):
+ def __init__(self, hashmod, oid):
+ unittest.TestCase.__init__(self)
+ self.hashmod = hashmod
+ self.oid = oid
+
+ def runTest(self):
+ h = self.hashmod.new()
+ if self.oid==None:
+ self.assertRaises(AttributeError, lambda: h.oid)
+ else:
+ self.assertEqual(h.oid, self.oid)
+
class MACSelfTest(unittest.TestCase):
def __init__(self, hashmod, description, expected_dict, input, key, hashmods):
@@ -116,7 +129,7 @@ class MACSelfTest(unittest.TestCase):
self.assertEqual(expected, out4)
self.assertEqual(expected, out5)
-def make_hash_tests(module, module_name, test_data):
+def make_hash_tests(module, module_name, test_data, oid=None):
tests = []
for i in range(len(test_data)):
row = test_data[i]
@@ -127,6 +140,7 @@ def make_hash_tests(module, module_name, test_data):
(expected, input, description) = row
name = "%s #%d: %s" % (module_name, i+1, description)
tests.append(HashSelfTest(module, name, expected, input))
+ tests.append(HashTestOID(module, oid))
return tests
def make_mac_tests(module, module_name, test_data, hashmods):
diff --git a/lib/Crypto/SelfTest/Hash/test_MD2.py b/lib/Crypto/SelfTest/Hash/test_MD2.py
index 02f08ec..32e5221 100644
--- a/lib/Crypto/SelfTest/Hash/test_MD2.py
+++ b/lib/Crypto/SelfTest/Hash/test_MD2.py
@@ -50,7 +50,7 @@ test_data = [
def get_tests(config={}):
from Crypto.Hash import MD2
from common import make_hash_tests
- return make_hash_tests(MD2, "MD2", test_data)
+ return make_hash_tests(MD2, "MD2", test_data, "\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x02")
if __name__ == '__main__':
import unittest
diff --git a/lib/Crypto/SelfTest/Hash/test_MD4.py b/lib/Crypto/SelfTest/Hash/test_MD4.py
index 21fe398..89dc789 100644
--- a/lib/Crypto/SelfTest/Hash/test_MD4.py
+++ b/lib/Crypto/SelfTest/Hash/test_MD4.py
@@ -50,7 +50,7 @@ test_data = [
def get_tests(config={}):
from Crypto.Hash import MD4
from common import make_hash_tests
- return make_hash_tests(MD4, "MD4", test_data)
+ return make_hash_tests(MD4, "MD4", test_data, "\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x04")
if __name__ == '__main__':
import unittest
diff --git a/lib/Crypto/SelfTest/Hash/test_MD5.py b/lib/Crypto/SelfTest/Hash/test_MD5.py
index 20fc353..a20f401 100644
--- a/lib/Crypto/SelfTest/Hash/test_MD5.py
+++ b/lib/Crypto/SelfTest/Hash/test_MD5.py
@@ -50,7 +50,7 @@ test_data = [
def get_tests(config={}):
from Crypto.Hash import MD5
from common import make_hash_tests
- return make_hash_tests(MD5, "MD5", test_data)
+ return make_hash_tests(MD5, "MD5", test_data, "\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x05")
if __name__ == '__main__':
import unittest
diff --git a/lib/Crypto/SelfTest/Hash/test_RIPEMD.py b/lib/Crypto/SelfTest/Hash/test_RIPEMD.py
index aa62222..8d686e5 100644
--- a/lib/Crypto/SelfTest/Hash/test_RIPEMD.py
+++ b/lib/Crypto/SelfTest/Hash/test_RIPEMD.py
@@ -59,7 +59,7 @@ test_data = [
def get_tests(config={}):
from Crypto.Hash import RIPEMD
from common import make_hash_tests
- return make_hash_tests(RIPEMD, "RIPEMD", test_data)
+ return make_hash_tests(RIPEMD, "RIPEMD", test_data, "\x06\x05\x2b\x24\x03\02\x01")
if __name__ == '__main__':
import unittest
diff --git a/lib/Crypto/SelfTest/Hash/test_SHA.py b/lib/Crypto/SelfTest/Hash/test_SHA.py
index 28ed169..4b2d490 100644
--- a/lib/Crypto/SelfTest/Hash/test_SHA.py
+++ b/lib/Crypto/SelfTest/Hash/test_SHA.py
@@ -50,7 +50,7 @@ test_data = [
def get_tests(config={}):
from Crypto.Hash import SHA
from common import make_hash_tests
- return make_hash_tests(SHA, "SHA", test_data)
+ return make_hash_tests(SHA, "SHA", test_data, "\x06\x05\x2B\x0E\x03\x02\x1A")
if __name__ == '__main__':
import unittest
diff --git a/lib/Crypto/SelfTest/Hash/test_SHA256.py b/lib/Crypto/SelfTest/Hash/test_SHA256.py
index 2997643..a43608e 100644
--- a/lib/Crypto/SelfTest/Hash/test_SHA256.py
+++ b/lib/Crypto/SelfTest/Hash/test_SHA256.py
@@ -72,7 +72,7 @@ def get_tests(config={}):
from Crypto.Hash import SHA256
from common import make_hash_tests
- tests = make_hash_tests(SHA256, "SHA256", test_data)
+ tests = make_hash_tests(SHA256, "SHA256", test_data, "\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01")
if config.get('slow_tests'):
tests += [LargeSHA256Test()]