test_rfc3279.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. import sys
  9. import unittest
  10. from pyasn1.codec.der.decoder import decode as der_decoder
  11. from pyasn1.codec.der.encoder import encode as der_encoder
  12. from pyasn1.type import univ
  13. from pyasn1_modules import pem
  14. from pyasn1_modules import rfc5280
  15. from pyasn1_modules import rfc3279
  16. class RSACertificateTestCase(unittest.TestCase):
  17. rsa_cert_pem_text = """\
  18. MIIE8TCCA9mgAwIBAgIQbyXcFa/fXqMIVgw7ek/H+DANBgkqhkiG9w0BAQUFADBv
  19. MQswCQYDVQQGEwJTRTEUMBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFk
  20. ZFRydXN0IEV4dGVybmFsIFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBF
  21. eHRlcm5hbCBDQSBSb290MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFow
  22. gYExCzAJBgNVBAYTAkdCMRswGQYDVQQIExJHcmVhdGVyIE1hbmNoZXN0ZXIxEDAO
  23. BgNVBAcTB1NhbGZvcmQxGjAYBgNVBAoTEUNPTU9ETy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QNzPeP2S35S6jJQzVMx0Njav2fkZ7WQaS44LE5/X289kF
  40. z0k0LTdf9CXH8PtrI3fx8UDXTLtJRTHdAChntylMdagfeTHJNjcPyjVPjPF+3vxG
  41. q79om3AjMC63xVx7ivsYE3lLkkKM3CyrbCK3KFOzGkrOG/soDrc6pNoN90AyT99v
  42. uwFQ/IfTdtn8+7aEA8rJNhj33Wzbu7qBHKat/ij5z7micV0ZBepKRtxzQe+JlEKx
  43. Q4hvNRevHmCDrHqMEHufyfaDbZ76iO4+3e6esL/garnQnweyCROa9aTlyFt5p0c1
  44. M2jlVZ6qW8swC53HD79oRIGXi1FK
  45. """
  46. def setUp(self):
  47. self.asn1Spec = rfc5280.Certificate()
  48. def testDerCodec(self):
  49. substrate = pem.readBase64fromText(self.rsa_cert_pem_text)
  50. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  51. self.assertFalse(rest)
  52. self.assertTrue(asn1Object.prettyPrint())
  53. self.assertEqual(substrate, der_encoder(asn1Object))
  54. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  55. self.assertEqual(rfc3279.rsaEncryption, spki_a['algorithm'])
  56. spki_pk = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'].asOctets()
  57. pk, rest = der_decoder(spki_pk, asn1Spec=rfc3279.RSAPublicKey())
  58. self.assertFalse(rest)
  59. self.assertTrue(pk.prettyPrint())
  60. self.assertEqual(spki_pk, der_encoder(pk))
  61. self.assertEqual(65537, pk['publicExponent'])
  62. self.assertEqual(rfc3279.sha1WithRSAEncryption,
  63. asn1Object['tbsCertificate']['signature']['algorithm'])
  64. self.assertEqual(rfc3279.sha1WithRSAEncryption,
  65. asn1Object['signatureAlgorithm']['algorithm'])
  66. def testOpenTypes(self):
  67. substrate = pem.readBase64fromText(self.rsa_cert_pem_text)
  68. asn1Object, rest = der_decoder(
  69. substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)
  70. self.assertFalse(rest)
  71. self.assertTrue(asn1Object.prettyPrint())
  72. self.assertEqual(substrate, der_encoder(asn1Object))
  73. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  74. self.assertEqual(rfc3279.rsaEncryption, spki_a['algorithm'])
  75. self.assertEqual(univ.Null(""), spki_a['parameters'])
  76. class ECCertificateTestCase(unittest.TestCase):
  77. ec_cert_pem_text = """\
  78. MIIDrDCCApSgAwIBAgIQCssoukZe5TkIdnRw883GEjANBgkqhkiG9w0BAQwFADBh
  79. MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
  80. d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
  81. QTAeFw0xMzAzMDgxMjAwMDBaFw0yMzAzMDgxMjAwMDBaMEwxCzAJBgNVBAYTAlVT
  82. MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxJjAkBgNVBAMTHURpZ2lDZXJ0IEVDQyBT
  83. ZWN1cmUgU2VydmVyIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE4ghC6nfYJN6g
  84. LGSkE85AnCNyqQIKDjc/ITa4jVMU9tWRlUvzlgKNcR7E2Munn17voOZ/WpIRllNv
  85. 68DLP679Wz9HJOeaBy6Wvqgvu1cYr3GkvXg6HuhbPGtkESvMNCuMo4IBITCCAR0w
  86. EgYDVR0TAQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwNAYIKwYBBQUHAQEE
  87. KDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5jb20wQgYDVR0f
  88. BDswOTA3oDWgM4YxaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL0RpZ2lDZXJ0R2xv
  89. YmFsUm9vdENBLmNybDA9BgNVHSAENjA0MDIGBFUdIAAwKjAoBggrBgEFBQcCARYc
  90. aHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzAdBgNVHQ4EFgQUo53mH/naOU/A
  91. buiRy5Wl2jHiCp8wHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUwDQYJ
  92. KoZIhvcNAQEMBQADggEBAMeKoENL7HTJxavVHzA1Nm6YVntIrAVjrnuaVyRXzG/6
  93. 3qttnMe2uuzO58pzZNvfBDcKAEmzP58mrZGMIOgfiA4q+2Y3yDDo0sIkp0VILeoB
  94. UEoxlBPfjV/aKrtJPGHzecicZpIalir0ezZYoyxBEHQa0+1IttK7igZFcTMQMHp6
  95. mCHdJLnsnLWSB62DxsRq+HfmNb4TDydkskO/g+l3VtsIh5RHFPVfKK+jaEyDj2D3
  96. loB5hWp2Jp2VDCADjT7ueihlZGak2YPqmXTNbk19HOuNssWvFhtOyPNV6og4ETQd
  97. Ea8/B6hPatJ0ES8q/HO3X8IVQwVs1n3aAr0im0/T+Xc=
  98. """
  99. def setUp(self):
  100. self.asn1Spec = rfc5280.Certificate()
  101. def testDerCodec(self):
  102. substrate = pem.readBase64fromText(self.ec_cert_pem_text)
  103. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  104. self.assertFalse(rest)
  105. self.assertTrue(asn1Object.prettyPrint())
  106. self.assertEqual(substrate, der_encoder(asn1Object))
  107. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  108. self.assertEqual(rfc3279.id_ecPublicKey, spki_a['algorithm'])
  109. spki_a_p, rest = der_decoder(
  110. spki_a['parameters'], asn1Spec=rfc3279.EcpkParameters())
  111. self.assertFalse(rest)
  112. self.assertTrue(spki_a_p.prettyPrint())
  113. self.assertEqual(spki_a['parameters'], der_encoder(spki_a_p))
  114. self.assertEqual(univ.ObjectIdentifier('1.3.132.0.34'), spki_a_p['namedCurve'])
  115. def testOpenTypes(self):
  116. substrate = pem.readBase64fromText(self.ec_cert_pem_text)
  117. asn1Object, rest = der_decoder(
  118. substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)
  119. self.assertFalse(rest)
  120. self.assertTrue(asn1Object.prettyPrint())
  121. self.assertEqual(substrate, der_encoder(asn1Object))
  122. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  123. self.assertEqual(rfc3279.id_ecPublicKey, spki_a['algorithm'])
  124. self.assertEqual(
  125. univ.ObjectIdentifier('1.3.132.0.34'), spki_a['parameters']['namedCurve'])
  126. class DSACertificateTestCase(unittest.TestCase):
  127. dsa_cert_pem_text = """\
  128. MIIDpjCCA0ygAwIBAgIUY8xt3l0B9nIPWSpjs0hDJUJZmCkwCwYJYIZIAWUDBAMC
  129. MD8xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJWQTEQMA4GA1UEBxMHSGVybmRvbjER
  130. MA8GA1UEChMIQm9ndXMgQ0EwHhcNMTkxMDIwMjAxMjMwWhcNMjAxMDE5MjAxMjMw
  131. WjBwMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVkExEDAOBgNVBAcTB0hlcm5kb24x
  132. EDAOBgNVBAoTB0V4YW1wbGUxDjAMBgNVBAsTBUFsaWNlMSAwHgYJKoZIhvcNAQkB
  133. FhFhbGljZUBleGFtcGxlLmNvbTCCAbYwggErBgcqhkjOOAQBMIIBHgKBgQCLpR53
  134. xHfe+SiknAK/L9lm/ZO1109c9iYkriPIW/5MMlM+qc/tdRkKpG6ELIpfXTPtKCJm
  135. zqqVIyTmAJryyE8Xw0Ie2mzYPU5ULvKmllQkjTsWgPGgQBkciZ0AW9ggD9VwZilg
  136. 4qh3iSO7T97hVQFnpCh6vm8pOH6UP/5kpr9ZJQIVANzdbztBJlJfqCB1t4h/NvSu
  137. wCFvAoGAITP+jhYk9Rngd98l+5ccgauQ+cLEUBgNG2Wq56zBXQbLou6eKkQi7ecL
  138. NiRmExq3IU3LOj426wSxL72Kw6FPyOEv3edIFkJJEHL4Z+ZJeVe//dzya0ddOJ7k
  139. k6qNF2ic+viD/5Vm8yRyKiig2uHH/MgIesLdZnvbzvX+f/P0z50DgYQAAoGALAUl
  140. jkOi1PxjjFVvhGfK95yIsrfbfcIEKUBaTs9NR2rbGWUeP+93paoXwP39X9wrJx2M
  141. SWeHWhWKszNgoiyqYT0k4R9mem3WClotxOvB5fHfwIp2kQYvE7H0/TPdGhfUpHQG
  142. YpyLQgT6L80meSKMFnu4VXGzOANhWDxu3JxiADCjgZQwgZEwCwYDVR0PBAQDAgeA
  143. MEIGCWCGSAGG+EIBDQQ1FjNUaGlzIGNlcnRpZmljYXRlIGNhbm5vdCBiZSB0cnVz
  144. dGVkIGZvciBhbnkgcHVycG9zZS4wHQYDVR0OBBYEFO37wHcauyc03rDc6cDRRsHz
  145. gcK+MB8GA1UdIwQYMBaAFM1IZQGDsqYHWwb+I4EMxHPk0bU4MAsGCWCGSAFlAwQD
  146. AgNHADBEAiBBRbfMzLi7+SVyO8SM3xxwUsMf/k1B+Nkvf1kBTfCfGwIgSAx/6mI+
  147. pNqdXqZZGESXy1MT1aBc4ynPGLFUr2r7cPY=
  148. """
  149. def setUp(self):
  150. self.asn1Spec = rfc5280.Certificate()
  151. def testDerCodec(self):
  152. substrate = pem.readBase64fromText(self.dsa_cert_pem_text)
  153. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  154. self.assertFalse(rest)
  155. self.assertTrue(asn1Object.prettyPrint())
  156. self.assertEqual(substrate, der_encoder(asn1Object))
  157. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  158. self.assertEqual(rfc3279.id_dsa, spki_a['algorithm'])
  159. spki_a_p, rest = der_decoder(spki_a['parameters'],
  160. asn1Spec=rfc3279.Dss_Parms())
  161. self.assertFalse(rest)
  162. self.assertTrue(spki_a_p.prettyPrint())
  163. self.assertEqual(spki_a['parameters'], der_encoder(spki_a_p))
  164. q_value = 1260916123897116834511257683105158021801897369967
  165. self.assertEqual(q_value, spki_a_p['q'])
  166. sig_value, rest = der_decoder(
  167. asn1Object['signature'].asOctets(), asn1Spec=rfc3279.Dss_Sig_Value())
  168. self.assertFalse(rest)
  169. self.assertTrue(sig_value.prettyPrint())
  170. self.assertEqual(asn1Object['signature'].asOctets(), der_encoder(sig_value))
  171. self.assertTrue(sig_value['r'].hasValue())
  172. self.assertTrue(sig_value['s'].hasValue())
  173. def testOpenTypes(self):
  174. substrate = pem.readBase64fromText(self.dsa_cert_pem_text)
  175. asn1Object, rest = der_decoder(
  176. substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)
  177. self.assertFalse(rest)
  178. self.assertTrue(asn1Object.prettyPrint())
  179. self.assertEqual(substrate, der_encoder(asn1Object))
  180. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  181. self.assertEqual(rfc3279.id_dsa, spki_a['algorithm'])
  182. q_value = 1260916123897116834511257683105158021801897369967
  183. self.assertEqual(q_value, spki_a['parameters']['q'])
  184. class KEACertificateTestCase(unittest.TestCase):
  185. kea_cert_pem_text = """\
  186. MIICizCCAjOgAwIBAgIUY8xt3l0B9nIPWSpjs0hDJUJZmCgwCQYHKoZIzjgEAzA/
  187. MQswCQYDVQQGEwJVUzELMAkGA1UECBMCVkExEDAOBgNVBAcTB0hlcm5kb24xETAP
  188. BgNVBAoTCEJvZ3VzIENBMB4XDTE5MTAyMDIwMDkyMVoXDTIwMTAxOTIwMDkyMVow
  189. cDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlZBMRAwDgYDVQQHEwdIZXJuZG9uMRAw
  190. DgYDVQQKEwdFeGFtcGxlMQ4wDAYDVQQDEwVBbGljZTEgMB4GCSqGSIb3DQEJARYR
  191. YWxpY2VAZXhhbXBsZS5jb20wgaAwFwYJYIZIAWUCAQEWBApc+PEn5ladbYizA4GE
  192. AAKBgB9Lc2QcoSW0E9/VnQ2xGBtpYh9MaDUBzIixbN8rhDwh0BBesD2TwHjzBpDM
  193. 2PJ6DD1ZbBcz2M3vJaIKoZ8hA2EUtbbHX1BSnVfAdeqr5St5gfnuxSdloUjLQlWO
  194. rOYfpFVEp6hJoKAZiYfiXz0fohNXn8+fiU5k214byxlCPlU0o4GUMIGRMAsGA1Ud
  195. DwQEAwIDCDBCBglghkgBhvhCAQ0ENRYzVGhpcyBjZXJ0aWZpY2F0ZSBjYW5ub3Qg
  196. YmUgdHJ1c3RlZCBmb3IgYW55IHB1cnBvc2UuMB0GA1UdDgQWBBSE49bkPB9sQm27
  197. Rs2jgAPMyY6UCDAfBgNVHSMEGDAWgBTNSGUBg7KmB1sG/iOBDMRz5NG1ODAJBgcq
  198. hkjOOAQDA0cAMEQCIE9PWhUbnJVdNQcVYSc36BMZ+23uk2ITLsgSXtkScF6TAiAf
  199. TPnJ5Wym0hv2fOpnPPsWTgqvLFYfX27GGTquuOd/6A==
  200. """
  201. def setUp(self):
  202. self.asn1Spec = rfc5280.Certificate()
  203. def testDerCodec(self):
  204. substrate = pem.readBase64fromText(self.kea_cert_pem_text)
  205. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  206. self.assertFalse(rest)
  207. self.assertTrue(asn1Object.prettyPrint())
  208. self.assertEqual(substrate, der_encoder(asn1Object))
  209. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  210. self.assertEqual(rfc3279.id_keyExchangeAlgorithm, spki_a['algorithm'])
  211. spki_a_p, rest = der_decoder(spki_a['parameters'],
  212. asn1Spec=rfc3279.KEA_Parms_Id())
  213. self.assertFalse(rest)
  214. self.assertTrue(spki_a_p.prettyPrint())
  215. self.assertEqual(spki_a['parameters'], der_encoder(spki_a_p))
  216. self.assertEqual(univ.OctetString(hexValue='5cf8f127e6569d6d88b3'), spki_a_p)
  217. self.assertEqual(
  218. rfc3279.id_dsa_with_sha1, asn1Object['tbsCertificate']['signature']['algorithm'])
  219. self.assertEqual(
  220. rfc3279.id_dsa_with_sha1, asn1Object['signatureAlgorithm']['algorithm'])
  221. sig_value, rest = der_decoder(asn1Object['signature'].asOctets(),
  222. asn1Spec=rfc3279.Dss_Sig_Value())
  223. self.assertFalse(rest)
  224. self.assertTrue(sig_value.prettyPrint())
  225. self.assertEqual(asn1Object['signature'].asOctets(), der_encoder(sig_value))
  226. self.assertTrue(sig_value['r'].hasValue())
  227. self.assertTrue(sig_value['s'].hasValue())
  228. def testOpenTypes(self):
  229. substrate = pem.readBase64fromText(self.kea_cert_pem_text)
  230. asn1Object, rest = der_decoder(
  231. substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)
  232. self.assertFalse(rest)
  233. self.assertTrue(asn1Object.prettyPrint())
  234. self.assertEqual(substrate, der_encoder(asn1Object))
  235. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  236. self.assertEqual(rfc3279.id_keyExchangeAlgorithm, spki_a['algorithm'])
  237. self.assertEqual(
  238. univ.OctetString(hexValue='5cf8f127e6569d6d88b3'), spki_a['parameters'])
  239. self.assertEqual(rfc3279.id_dsa_with_sha1,
  240. asn1Object['tbsCertificate']['signature']['algorithm'])
  241. self.assertEqual(
  242. rfc3279.id_dsa_with_sha1, asn1Object['signatureAlgorithm']['algorithm'])
  243. class DHCertificateTestCase(unittest.TestCase):
  244. dh_cert_pem_text = """\
  245. MIIEtDCCBFqgAwIBAgIUY8xt3l0B9nIPWSpjs0hDJUJZmCkwCwYJYIZIAWUDBAMC
  246. MD8xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJWQTEQMA4GA1UEBxMHSGVybmRvbjER
  247. MA8GA1UEChMIQm9ndXMgQ0EwHhcNMTkxMDIwMjAxMjMwWhcNMjAxMDE5MjAxMjMw
  248. WjBwMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVkExEDAOBgNVBAcTB0hlcm5kb24x
  249. EDAOBgNVBAoTB0V4YW1wbGUxDjAMBgNVBAsTBUFsaWNlMSAwHgYJKoZIhvcNAQkB
  250. FhFhbGljZUBleGFtcGxlLmNvbTCCAsQwggI5BgcqhkjOPgIBMIICLAKCAQEAt9x/
  251. 0iwGww3k19h+wbODVK1yqjFzEY2pyfXthHcn+nEw+Dp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BYEFO37wHcauyc03rDc6cDRRsHzgcK+MB8GA1UdIwQYMBaAFM1I
  268. ZQGDsqYHWwb+I4EMxHPk0bU4MAsGCWCGSAFlAwQDAgNHADBEAiB1LU0esRdHDvSj
  269. kqAm+3viU2a+hl66sLrK5lYBOYqGYAIgWG7bDxqFVP6/stHfdbeMovLejquEl9tr
  270. iPEBA+EDHjk=
  271. """
  272. def setUp(self):
  273. self.asn1Spec = rfc5280.Certificate()
  274. def testDerCodec(self):
  275. substrate = pem.readBase64fromText(self.dh_cert_pem_text)
  276. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  277. self.assertFalse(rest)
  278. self.assertTrue(asn1Object.prettyPrint())
  279. self.assertEqual(substrate, der_encoder(asn1Object))
  280. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  281. self.assertEqual(rfc3279.dhpublicnumber, spki_a['algorithm'])
  282. spki_a_p, rest = der_decoder(
  283. spki_a['parameters'], asn1Spec=rfc3279.DomainParameters())
  284. self.assertFalse(rest)
  285. self.assertTrue(spki_a_p.prettyPrint())
  286. self.assertEqual(spki_a['parameters'], der_encoder(spki_a_p))
  287. q_value = 65838278260281264030127352144753816831178774189428428256716126077244217603537
  288. self.assertEqual(q_value, spki_a_p['q'])
  289. def testOpenTypes(self):
  290. substrate = pem.readBase64fromText(self.dh_cert_pem_text)
  291. asn1Object, rest = der_decoder(substrate,
  292. asn1Spec=self.asn1Spec,
  293. decodeOpenTypes=True)
  294. self.assertFalse(rest)
  295. self.assertTrue(asn1Object.prettyPrint())
  296. self.assertEqual(substrate, der_encoder(asn1Object))
  297. spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']
  298. self.assertEqual(rfc3279.dhpublicnumber, spki_a['algorithm'])
  299. q_value = 65838278260281264030127352144753816831178774189428428256716126077244217603537
  300. self.assertEqual(q_value, spki_a['parameters']['q'])
  301. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  302. if __name__ == '__main__':
  303. unittest.TextTestRunner(verbosity=2).run(suite)