• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.decoder import decode as der_decode
12from pyasn1.codec.der.encoder import encode as der_encode
13
14from pyasn1.type import univ
15
16from pyasn1_modules import pem
17from pyasn1_modules import rfc2631
18
19try:
20    import unittest2 as unittest
21except ImportError:
22    import unittest
23
24
25class OtherInfoTestCase(unittest.TestCase):
26    pem_text = "MB0wEwYLKoZIhvcNAQkQAwYEBAAAAAGiBgQEAAAAwA=="
27
28    def setUp(self):
29        self.asn1Spec = rfc2631.OtherInfo()
30
31    def testDerCodec(self):
32        substrate = pem.readBase64fromText(self.pem_text)
33        asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec)
34        assert not rest
35        assert asn1Object.prettyPrint()
36        assert der_encode(asn1Object) == substrate
37
38        hex1 = univ.OctetString(hexValue='00000001')
39        assert asn1Object['keyInfo']['counter'] == hex1
40
41
42suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
43
44if __name__ == '__main__':
45    import sys
46
47    result = unittest.TextTestRunner(verbosity=2).run(suite)
48    sys.exit(not result.wasSuccessful())
49