• 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 rfc5280
16from pyasn1_modules import rfc3560
17
18try:
19    import unittest2 as unittest
20except ImportError:
21    import unittest
22
23
24class OAEPDefautTestCase(unittest.TestCase):
25    oaep_default_pem_text = "MAsGCSqGSIb3DQEBBw=="
26
27    def setUp(self):
28        self.asn1Spec = rfc5280.AlgorithmIdentifier()
29
30    def testDerCodec(self):
31        substrate = pem.readBase64fromText(self.oaep_default_pem_text)
32        asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
33        assert not rest
34        assert asn1Object.prettyPrint()
35        assert asn1Object[0] == rfc3560.id_RSAES_OAEP
36        assert der_encoder.encode(asn1Object) == substrate
37        assert substrate == der_encoder.encode(asn1Object)
38
39
40class OAEPSHA256TestCase(unittest.TestCase):
41    oaep_sha256_pem_text = "MDwGCSqGSIb3DQEBBzAvoA8wDQYJYIZIAWUDBAIBBQChHDAaBgkqhkiG9w0BAQgwDQYJYIZIAWUDBAIBBQA="
42
43    def setUp(self):
44        self.asn1Spec = rfc5280.AlgorithmIdentifier()
45
46    def testDerCodec(self):
47        substrate = pem.readBase64fromText(self.oaep_sha256_pem_text)
48        asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
49        assert not rest
50        assert asn1Object.prettyPrint()
51        assert asn1Object[0] == rfc3560.id_RSAES_OAEP
52        assert der_encoder.encode(asn1Object) == substrate
53        assert substrate == der_encoder.encode(asn1Object)
54
55
56class OAEPFullTestCase(unittest.TestCase):
57    oaep_full_pem_text = "MFMGCSqGSIb3DQEBBzBGoA8wDQYJYIZIAWUDBAICBQChHDAaBgkqhkiG9w0BAQgwDQYJYIZIAWUDBAICBQCiFTATBgkqhkiG9w0BAQkEBmZvb2Jhcg=="
58
59    def setUp(self):
60        self.asn1Spec = rfc5280.AlgorithmIdentifier()
61
62    def testDerCodec(self):
63        substrate = pem.readBase64fromText(self.oaep_full_pem_text)
64        asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
65        assert not rest
66        assert asn1Object.prettyPrint()
67        assert asn1Object[0] == rfc3560.id_RSAES_OAEP
68        assert der_encoder.encode(asn1Object) == substrate
69        assert substrate == der_encoder.encode(asn1Object)
70
71
72suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
73
74if __name__ == '__main__':
75    import sys
76
77    result = unittest.TextTestRunner(verbosity=2).run(suite)
78    sys.exit(not result.wasSuccessful())
79