當前位置: 首頁>>代碼示例>>Python>>正文


Python oid.ObjectIdentifier方法代碼示例

本文整理匯總了Python中cryptography.x509.oid.ObjectIdentifier方法的典型用法代碼示例。如果您正苦於以下問題:Python oid.ObjectIdentifier方法的具體用法?Python oid.ObjectIdentifier怎麽用?Python oid.ObjectIdentifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cryptography.x509.oid的用法示例。


在下文中一共展示了oid.ObjectIdentifier方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def __init__(self, oid, value):
        if not isinstance(oid, ObjectIdentifier):
            raise TypeError(
                "oid argument must be an ObjectIdentifier instance."
            )

        if not isinstance(value, six.text_type):
            raise TypeError(
                "value argument must be a text type."
            )

        if oid == NameOID.COUNTRY_NAME and len(value.encode("utf8")) != 2:
            raise ValueError(
                "Country name must be a 2 character country code"
            )

        self._oid = oid
        self._value = value 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:20,代碼來源:name.py

示例2: test_config

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def test_config(self):
        self.assertTrue(issubclass(self.ext_class, Extension))
        self.assertEqual(self.ext_class.key, self.ext_class_key)
        self.assertEqual(self.ext_class.name, self.ext_class_name)

        # Test some basic properties (just to be sure)
        self.assertIsInstance(self.ext_class.oid, ObjectIdentifier)
        self.assertIsInstance(self.ext_class.key, str)
        self.assertGreater(len(self.ext_class.key), 0)
        self.assertIsInstance(self.ext_class.name, str)
        self.assertGreater(len(self.ext_class.name), 0)

        # Test mapping dicts
        self.assertEqual(KEY_TO_EXTENSION[self.ext_class.key], self.ext_class)
        self.assertEqual(OID_TO_EXTENSION[self.ext_class.oid], self.ext_class)

        # test that the model matches
        self.assertTrue(hasattr(X509CertMixin, self.ext_class.key))
        self.assertIsInstance(getattr(X509CertMixin, self.ext_class.key), cached_property) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:21,代碼來源:tests_extensions.py

示例3: oid_to_json

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def oid_to_json(obj: ObjectIdentifier) -> Dict[str, str]:
    return {"name": obj._name, "dotted_string": obj.dotted_string}


# We use dataclasses here to ensure consistency in how we serialize X509 names 
開發者ID:nabla-c0d3,項目名稱:sslyze,代碼行數:7,代碼來源:_json_output.py

示例4: __init__

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def __init__(self, oid, value):
        if not isinstance(oid, ObjectIdentifier):
            raise TypeError(
                "oid argument must be an ObjectIdentifier instance."
            )

        if not isinstance(value, six.text_type):
            raise TypeError(
                "value argument must be a text type."
            )

        self._oid = oid
        self._value = value 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:15,代碼來源:name.py

示例5: __init__

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def __init__(self, value):
        if not isinstance(value, ObjectIdentifier):
            raise TypeError("value must be an ObjectIdentifier")

        self._value = value 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:7,代碼來源:general_name.py

示例6: __init__

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def __init__(self, oid, value, _type=_SENTINEL):
        if not isinstance(oid, ObjectIdentifier):
            raise TypeError(
                "oid argument must be an ObjectIdentifier instance."
            )

        if not isinstance(value, six.text_type):
            raise TypeError(
                "value argument must be a text type."
            )

        if (
            oid == NameOID.COUNTRY_NAME or
            oid == NameOID.JURISDICTION_COUNTRY_NAME
        ):
            if len(value.encode("utf8")) != 2:
                raise ValueError(
                    "Country name must be a 2 character country code"
                )

        if len(value) == 0:
            raise ValueError("Value cannot be an empty string")

        # The appropriate ASN1 string type varies by OID and is defined across
        # multiple RFCs including 2459, 3280, and 5280. In general UTF8String
        # is preferred (2459), but 3280 and 5280 specify several OIDs with
        # alternate types. This means when we see the sentinel value we need
        # to look up whether the OID has a non-UTF8 type. If it does, set it
        # to that. Otherwise, UTF8!
        if _type == _SENTINEL:
            _type = _NAMEOID_DEFAULT_TYPE.get(oid, _ASN1Type.UTF8String)

        if not isinstance(_type, _ASN1Type):
            raise TypeError("_type must be from the _ASN1Type enum")

        self._oid = oid
        self._value = value
        self._type = _type 
開發者ID:tp4a,項目名稱:teleport,代碼行數:40,代碼來源:name.py

示例7: __init__

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def __init__(self, oid, value, _type=_SENTINEL):
        if not isinstance(oid, ObjectIdentifier):
            raise TypeError(
                "oid argument must be an ObjectIdentifier instance."
            )

        if not isinstance(value, six.text_type):
            raise TypeError(
                "value argument must be a text type."
            )

        if (
            oid == NameOID.COUNTRY_NAME or
            oid == NameOID.JURISDICTION_COUNTRY_NAME
        ):
            if len(value.encode("utf8")) != 2:
                raise ValueError(
                    "Country name must be a 2 character country code"
                )

        # The appropriate ASN1 string type varies by OID and is defined across
        # multiple RFCs including 2459, 3280, and 5280. In general UTF8String
        # is preferred (2459), but 3280 and 5280 specify several OIDs with
        # alternate types. This means when we see the sentinel value we need
        # to look up whether the OID has a non-UTF8 type. If it does, set it
        # to that. Otherwise, UTF8!
        if _type == _SENTINEL:
            _type = _NAMEOID_DEFAULT_TYPE.get(oid, _ASN1Type.UTF8String)

        if not isinstance(_type, _ASN1Type):
            raise TypeError("_type must be from the _ASN1Type enum")

        self._oid = oid
        self._value = value
        self._type = _type 
開發者ID:tp4a,項目名稱:teleport,代碼行數:37,代碼來源:name.py

示例8: policy_identifier

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def policy_identifier(self, value):
        if isinstance(value, str):
            value = ObjectIdentifier(value)
        self._policy_identifier = value 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:6,代碼來源:extensions.py

示例9: parse_value

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def parse_value(self, v):
        if isinstance(v, ObjectIdentifier) and v in self._CRYPTOGRAPHY_MAPPING_REVERSED:
            return v
        elif isinstance(v, str) and v in self.CRYPTOGRAPHY_MAPPING:
            return self.CRYPTOGRAPHY_MAPPING[v]
        raise ValueError('Unknown value: %s' % v) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:8,代碼來源:extensions.py

示例10: test_policy_identifier_setter

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def test_policy_identifier_setter(self):
        value = '1.2.3'
        expected = ObjectIdentifier(value)
        pi = PolicyInformation({'policy_identifier': value})
        pi.policy_identifier = value
        self.assertEqual(pi.policy_identifier, expected)

        pi = PolicyInformation({'policy_identifier': expected})
        self.assertEqual(pi.policy_identifier, expected)

        new_value = '2.3.4'
        new_expected = ObjectIdentifier(new_value)
        pi.policy_identifier = new_value
        self.assertEqual(pi.policy_identifier, new_expected) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:16,代碼來源:tests_extensions.py

示例11: test_completeness

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def test_completeness(self):
        # make sure we support all ExtendedKeyUsageOIDs
        for attr in [getattr(ExtendedKeyUsageOID, a) for a in dir(ExtendedKeyUsageOID) if a[0] != '_']:
            if isinstance(attr, ObjectIdentifier):
                self.assertIn(attr, ExtendedKeyUsage._CRYPTOGRAPHY_MAPPING_REVERSED)

        # make sure we haven't forgotton any keys in the form selection
        self.assertEqual(set(ExtendedKeyUsage.CRYPTOGRAPHY_MAPPING.keys()),
                         set([e[0] for e in ExtendedKeyUsage.CHOICES])) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:11,代碼來源:tests_extensions.py

示例12: __init__

# 需要導入模塊: from cryptography.x509 import oid [as 別名]
# 或者: from cryptography.x509.oid import ObjectIdentifier [as 別名]
def __init__(self, oid, value, _type=_SENTINEL):
        if not isinstance(oid, ObjectIdentifier):
            raise TypeError(
                "oid argument must be an ObjectIdentifier instance."
            )

        if not isinstance(value, six.text_type):
            raise TypeError(
                "value argument must be a text type."
            )

        if (
            oid == NameOID.COUNTRY_NAME or
            oid == NameOID.JURISDICTION_COUNTRY_NAME
        ):
            if len(value.encode("utf8")) != 2:
                raise ValueError(
                    "Country name must be a 2 character country code"
                )

            if _type == _SENTINEL:
                _type = _ASN1Type.PrintableString

        if len(value) == 0:
            raise ValueError("Value cannot be an empty string")

        # Set the default string type for encoding ASN1 strings to UTF8. This
        # is the default for newer OpenSSLs for several years (1.0.1h+) and is
        # recommended in RFC 2459.
        if _type == _SENTINEL:
            _type = _ASN1Type.UTF8String

        if not isinstance(_type, _ASN1Type):
            raise TypeError("_type must be from the _ASN1Type enum")

        self._oid = oid
        self._value = value
        self._type = _type 
開發者ID:aws-quickstart,項目名稱:quickstart-git2s3,代碼行數:40,代碼來源:name.py


注:本文中的cryptography.x509.oid.ObjectIdentifier方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。