本文整理匯總了Python中cryptography.x509.RelativeDistinguishedName方法的典型用法代碼示例。如果您正苦於以下問題:Python x509.RelativeDistinguishedName方法的具體用法?Python x509.RelativeDistinguishedName怎麽用?Python x509.RelativeDistinguishedName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cryptography.x509
的用法示例。
在下文中一共展示了x509.RelativeDistinguishedName方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _decode_x509_name
# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import RelativeDistinguishedName [as 別名]
def _decode_x509_name(backend, x509_name):
count = backend._lib.X509_NAME_entry_count(x509_name)
attributes = []
prev_set_id = -1
for x in range(count):
entry = backend._lib.X509_NAME_get_entry(x509_name, x)
attribute = _decode_x509_name_entry(backend, entry)
set_id = backend._lib.Cryptography_X509_NAME_ENTRY_set(entry)
if set_id != prev_set_id:
attributes.append(set([attribute]))
else:
# is in the same RDN a previous entry
attributes[-1].add(attribute)
prev_set_id = set_id
return x509.Name(x509.RelativeDistinguishedName(rdn) for rdn in attributes)
示例2: _decode_x509_name
# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import RelativeDistinguishedName [as 別名]
def _decode_x509_name(backend, x509_name):
count = backend._lib.X509_NAME_entry_count(x509_name)
attributes = []
prev_set_id = -1
for x in range(count):
entry = backend._lib.X509_NAME_get_entry(x509_name, x)
attribute = _decode_x509_name_entry(backend, entry)
set_id = backend._lib.Cryptography_X509_NAME_ENTRY_set(entry)
if set_id != prev_set_id:
attributes.append({attribute})
else:
# is in the same RDN a previous entry
attributes[-1].add(attribute)
prev_set_id = set_id
return x509.Name(x509.RelativeDistinguishedName(rdn) for rdn in attributes)
示例3: format_relative_name
# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import RelativeDistinguishedName [as 別名]
def format_relative_name(name):
"""Convert a relative name (RDN) into a canonical form.
Examples::
>>> format_relative_name([('C', 'AT'), ('CN', 'example.com')])
'/C=AT/CN=example.com'
>>> format_relative_name(x509.RelativeDistinguishedName([
... x509.NameAttribute(NameOID.COMMON_NAME, u'example.com')
... ]))
'/CN=example.com'
"""
if isinstance(name, x509.RelativeDistinguishedName):
name = [(OID_NAME_MAPPINGS[s.oid], s.value) for s in name]
return '/%s' % ('/'.join(['%s=%s' % (force_text(k), force_text(v)) for k, v in name]))
示例4: x509_relative_name
# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import RelativeDistinguishedName [as 別名]
def x509_relative_name(name):
"""Parse a relative name (RDN) into a :py:class:`~cg:cryptography.x509.RelativeDistinguishedName`.
>>> x509_relative_name('/CN=example.com')
<RelativeDistinguishedName(CN=example.com)>
>>> x509_relative_name([('CN', 'example.com')])
<RelativeDistinguishedName(CN=example.com)>
"""
if isinstance(name, x509.RelativeDistinguishedName):
return name
elif isinstance(name, str):
name = parse_name(name)
return x509.RelativeDistinguishedName([
x509.NameAttribute(NAME_OID_MAPPINGS[typ], force_text(value)) for typ, value in name
])
示例5: _decode_distpoint
# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import RelativeDistinguishedName [as 別名]
def _decode_distpoint(backend, distpoint):
if distpoint.type == _DISTPOINT_TYPE_FULLNAME:
full_name = _decode_general_names(backend, distpoint.name.fullname)
return full_name, None
# OpenSSL code doesn't test for a specific type for
# relativename, everything that isn't fullname is considered
# relativename. Per RFC 5280:
#
# DistributionPointName ::= CHOICE {
# fullName [0] GeneralNames,
# nameRelativeToCRLIssuer [1] RelativeDistinguishedName }
rns = distpoint.name.relativename
rnum = backend._lib.sk_X509_NAME_ENTRY_num(rns)
attributes = set()
for i in range(rnum):
rn = backend._lib.sk_X509_NAME_ENTRY_value(
rns, i
)
backend.openssl_assert(rn != backend._ffi.NULL)
attributes.add(
_decode_x509_name_entry(backend, rn)
)
relative_name = x509.RelativeDistinguishedName(attributes)
return None, relative_name
示例6: test_format
# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import RelativeDistinguishedName [as 別名]
def test_format(self):
rdn = x509.RelativeDistinguishedName([x509.NameAttribute(NameOID.COMMON_NAME, u'example.com')])
self.assertEqual(format_relative_name([('C', 'AT'), ('CN', 'example.com')]), '/C=AT/CN=example.com')
self.assertEqual(format_relative_name(rdn), '/CN=example.com')
示例7: test_parse
# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import RelativeDistinguishedName [as 別名]
def test_parse(self):
expected = x509.RelativeDistinguishedName([x509.NameAttribute(NameOID.COMMON_NAME, u'example.com')])
self.assertEqual(x509_relative_name('/CN=example.com'), expected)
self.assertEqual(x509_relative_name([('CN', 'example.com')]), expected)
示例8: rdn
# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import RelativeDistinguishedName [as 別名]
def rdn(r): # just a shortcut
return x509.RelativeDistinguishedName([x509.NameAttribute(*t) for t in r])