def test_serialise(self): asn1 = rfc5280.Extension() asn1['extnID'] = univ.ObjectIdentifier('1.2.3.4') asn1['critical'] = False asn1['extnValue'] = "foobar" ext = extension.construct_extension(asn1) self.assertEqual(ext.as_der(), encoder.encode(asn1))
def test_construct(self): asn1 = rfc5280.Extension() asn1['extnID'] = univ.ObjectIdentifier('1.2.3.4') asn1['critical'] = False asn1['extnValue'] = "foobar" ext = extension.construct_extension(asn1) self.assertIsInstance(ext, extension.X509Extension)
def test_unknown_extension_str(self): asn1 = rfc5280.Extension() asn1['extnID'] = univ.ObjectIdentifier('1.2.3.4') asn1['critical'] = False asn1['extnValue'] = "foobar" ext = extension.X509Extension(asn1) self.assertEqual("1.2.3.4: <unknown>", str(ext))
def test_critical(self): asn1 = rfc5280.Extension() asn1['extnID'] = univ.ObjectIdentifier('1.2.3.4') asn1['critical'] = False asn1['extnValue'] = "foobar" ext = extension.construct_extension(asn1) self.assertFalse(ext.get_critical()) ext.set_critical(True) self.assertTrue(ext.get_critical())
def __init__(self, ext=None): if ext is None: if self.spec is None: raise errors.X509Error("cannot create generic extension") self._ext = rfc5280.Extension() self._ext['extnID'] = self._oid self._set_value(self._get_default_value()) else: if not isinstance(ext, rfc5280.Extension): raise errors.X509Error("extension has incorrect type") self._ext = ext