• 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 import decoder as der_decoder
12from pyasn1.codec.der import encoder as der_encoder
13
14from pyasn1_modules import pem
15from pyasn1_modules import rfc5208
16from pyasn1_modules import rfc8410
17
18try:
19    import unittest2 as unittest
20except ImportError:
21    import unittest
22
23
24class PrivateKeyTestCase(unittest.TestCase):
25    no_pub_key_pem_text = "MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC"
26
27    def setUp(self):
28        self.asn1Spec = rfc5208.PrivateKeyInfo()
29
30    def testDerCodec(self):
31        substrate = pem.readBase64fromText(self.no_pub_key_pem_text)
32        asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
33        assert not rest
34        assert asn1Object.prettyPrint()
35        assert asn1Object['privateKeyAlgorithm']['algorithm'] == rfc8410.id_Ed25519
36        assert asn1Object['privateKey'].isValue
37        assert asn1Object['privateKey'].prettyPrint()[0:10] == "0x0420d4ee"
38        assert der_encoder.encode(asn1Object) == substrate
39
40
41suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
42
43if __name__ == '__main__':
44    import sys
45
46    result = unittest.TextTestRunner(verbosity=2).run(suite)
47    sys.exit(not result.wasSuccessful())
48