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 rfc5280 16from pyasn1_modules import rfc8103 17 18try: 19 import unittest2 as unittest 20except ImportError: 21 import unittest 22 23 24class CAEADChaCha20Poly1305TestCase(unittest.TestCase): 25 alg_id_pem_text = "MBsGCyqGSIb3DQEJEAMSBAzK/rq++s7brd7K+Ig=" 26 27 def setUp(self): 28 self.asn1Spec = rfc5280.AlgorithmIdentifier() 29 30 def testDerCodec(self): 31 substrate = pem.readBase64fromText(self.alg_id_pem_text) 32 asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) 33 assert not rest 34 assert asn1Object.prettyPrint() 35 assert asn1Object[0] == rfc8103.id_alg_AEADChaCha20Poly1305 36 param, rest = der_decoder.decode(asn1Object[1], rfc8103.AEADChaCha20Poly1305Nonce()) 37 assert not rest 38 assert param.prettyPrint() 39 assert param == rfc8103.AEADChaCha20Poly1305Nonce(value='\xca\xfe\xba\xbe\xfa\xce\xdb\xad\xde\xca\xf8\x88') 40 assert der_encoder.encode(asn1Object) == substrate 41 42 43suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 44 45if __name__ == '__main__': 46 import sys 47 48 result = unittest.TextTestRunner(verbosity=2).run(suite) 49 sys.exit(not result.wasSuccessful()) 50 51 52