1# 2# This file is part of pyasn1-modules software. 3# 4# Created by Russ Housley 5# Copyright (c) 2019, Vigil Security, LLC 6# License: http://snmplabs.com/pyasn1/license.html 7# 8 9import sys 10 11from pyasn1.codec.der import decoder as der_decoder 12from pyasn1.codec.der import encoder as der_encoder 13 14from pyasn1_modules import pem 15from pyasn1_modules import rfc5649 16 17try: 18 import unittest2 as unittest 19except ImportError: 20 import unittest 21 22 23class AESKeyWrapTestCase(unittest.TestCase): 24 kw_alg_id_pem_text = "MAsGCWCGSAFlAwQBLQ==" 25 26 def setUp(self): 27 self.asn1Spec = rfc5649.AlgorithmIdentifier() 28 29 def testDerCodec(self): 30 substrate = pem.readBase64fromText(self.kw_alg_id_pem_text) 31 asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) 32 assert not rest 33 assert asn1Object.prettyPrint() 34 assert asn1Object[0] == rfc5649.id_aes256_wrap 35 assert der_encoder.encode(asn1Object) == substrate 36 37 38class AESKeyWrapWithPadTestCase(unittest.TestCase): 39 kw_pad_alg_id_pem_text = "MAsGCWCGSAFlAwQBMA==" 40 41 def setUp(self): 42 self.asn1Spec = rfc5649.AlgorithmIdentifier() 43 44 def testDerCodec(self): 45 substrate = pem.readBase64fromText(self.kw_pad_alg_id_pem_text) 46 asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) 47 assert not rest 48 assert asn1Object.prettyPrint() 49 assert asn1Object[0] == rfc5649.id_aes256_wrap_pad 50 assert der_encoder.encode(asn1Object) == substrate 51 52 53suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 54 55if __name__ == '__main__': 56 import sys 57 58 result = unittest.TextTestRunner(verbosity=2).run(suite) 59 sys.exit(not result.wasSuccessful()) 60