1# 2# This file is part of pyasn1-modules software. 3# 4# Copyright (c) 2019, Vigil Security, LLC 5# License: http://snmplabs.com/pyasn1/license.html 6# 7import sys 8 9from pyasn1.codec.der import decoder as der_decoder 10from pyasn1.codec.der import encoder as der_encoder 11 12from pyasn1_modules import pem 13from pyasn1_modules import rfc5280 14from pyasn1_modules import rfc8619 15 16try: 17 import unittest2 as unittest 18except ImportError: 19 import unittest 20 21 22class HKDFSHA256TestCase(unittest.TestCase): 23 alg_id_1_pem_text = "MA0GCyqGSIb3DQEJEAMc" 24 25 def setUp(self): 26 self.asn1Spec = rfc5280.AlgorithmIdentifier() 27 28 def testDerCodec(self): 29 30 substrate = pem.readBase64fromText(self.alg_id_1_pem_text) 31 32 asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) 33 34 assert not rest 35 assert asn1Object.prettyPrint() 36 assert der_encoder.encode(asn1Object) == substrate 37 38 assert asn1Object['algorithm'] == rfc8619.id_alg_hkdf_with_sha256 39 40 41class HKDFSHA384TestCase(unittest.TestCase): 42 alg_id_1_pem_text = "MA0GCyqGSIb3DQEJEAMd" 43 44 def setUp(self): 45 self.asn1Spec = rfc5280.AlgorithmIdentifier() 46 47 def testDerCodec(self): 48 49 substrate = pem.readBase64fromText(self.alg_id_1_pem_text) 50 51 asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) 52 53 assert not rest 54 assert asn1Object.prettyPrint() 55 assert der_encoder.encode(asn1Object) == substrate 56 57 assert asn1Object['algorithm'] == rfc8619.id_alg_hkdf_with_sha384 58 59 60class HKDFSHA512TestCase(unittest.TestCase): 61 alg_id_1_pem_text = "MA0GCyqGSIb3DQEJEAMe" 62 63 def setUp(self): 64 self.asn1Spec = rfc5280.AlgorithmIdentifier() 65 66 def testDerCodec(self): 67 68 substrate = pem.readBase64fromText(self.alg_id_1_pem_text) 69 70 asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) 71 72 assert not rest 73 assert asn1Object.prettyPrint() 74 assert der_encoder.encode(asn1Object) == substrate 75 76 assert asn1Object['algorithm'] == rfc8619.id_alg_hkdf_with_sha512 77 78 79suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 80 81if __name__ == '__main__': 82 import sys 83 84 result = unittest.TextTestRunner(verbosity=2).run(suite) 85 sys.exit(not result.wasSuccessful()) 86