本文整理汇总了Python中cryptography.x509.NoticeReference方法的典型用法代码示例。如果您正苦于以下问题:Python x509.NoticeReference方法的具体用法?Python x509.NoticeReference怎么用?Python x509.NoticeReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.x509
的用法示例。
在下文中一共展示了x509.NoticeReference方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_policy_qualifier
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import NoticeReference [as 别名]
def parse_policy_qualifier(self, qualifier):
if isinstance(qualifier, str):
return force_text(qualifier)
elif isinstance(qualifier, x509.UserNotice):
return qualifier
elif isinstance(qualifier, dict):
explicit_text = qualifier.get('explicit_text')
notice_reference = qualifier.get('notice_reference')
if isinstance(notice_reference, dict):
notice_reference = x509.NoticeReference(
organization=force_text(notice_reference.get('organization', '')),
notice_numbers=[int(i) for i in notice_reference.get('notice_numbers', [])]
)
elif notice_reference is None:
pass # extra branch to ensure test coverage
elif isinstance(notice_reference, x509.NoticeReference):
pass # extra branch to ensure test coverage
else:
raise ValueError('NoticeReference must be either None, a dict or an x509.NoticeReference')
return x509.UserNotice(explicit_text=explicit_text, notice_reference=notice_reference)
raise ValueError('PolicyQualifier must be string, dict or x509.UserNotice')
示例2: test_constructor
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import NoticeReference [as 别名]
def test_constructor(self):
# just some constructors that are otherwise not called
pi = PolicyInformation()
self.assertIsNone(pi.policy_identifier)
self.assertIsNone(pi.policy_qualifiers)
pi = PolicyInformation({
'policy_identifier': '1.2.3',
'policy_qualifiers': [
x509.UserNotice(notice_reference=None, explicit_text='foobar'),
],
})
# todo: test pi
pi = PolicyInformation({
'policy_identifier': '1.2.3',
'policy_qualifiers': [{
'notice_reference': x509.NoticeReference(organization='foobar', notice_numbers=[1]),
}],
})
# todo: test pi
示例3: _decode_user_notice
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import NoticeReference [as 别名]
def _decode_user_notice(backend, un):
explicit_text = None
notice_reference = None
if un.exptext != backend._ffi.NULL:
explicit_text = backend._asn1_string_to_utf8(un.exptext)
if un.noticeref != backend._ffi.NULL:
organization = backend._asn1_string_to_utf8(un.noticeref.organization)
num = backend._lib.sk_ASN1_INTEGER_num(
un.noticeref.noticenos
)
notice_numbers = []
for i in range(num):
asn1_int = backend._lib.sk_ASN1_INTEGER_value(
un.noticeref.noticenos, i
)
notice_num = backend._asn1_integer_to_int(asn1_int)
notice_numbers.append(notice_num)
notice_reference = x509.NoticeReference(
organization, notice_numbers
)
return x509.UserNotice(notice_reference, explicit_text)
示例4: _decode_user_notice
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import NoticeReference [as 别名]
def _decode_user_notice(backend, un):
explicit_text = None
notice_reference = None
if un.exptext != backend._ffi.NULL:
explicit_text = _asn1_string_to_utf8(backend, un.exptext)
if un.noticeref != backend._ffi.NULL:
organization = _asn1_string_to_utf8(
backend, un.noticeref.organization
)
num = backend._lib.sk_ASN1_INTEGER_num(
un.noticeref.noticenos
)
notice_numbers = []
for i in range(num):
asn1_int = backend._lib.sk_ASN1_INTEGER_value(
un.noticeref.noticenos, i
)
notice_num = _asn1_integer_to_int(backend, asn1_int)
notice_numbers.append(notice_num)
notice_reference = x509.NoticeReference(
organization, notice_numbers
)
return x509.UserNotice(notice_reference, explicit_text)
示例5: test_constructor_errors
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import NoticeReference [as 别名]
def test_constructor_errors(self):
with self.assertRaisesRegex(
ValueError, r'^PolicyInformation data must be either x509.PolicyInformation or dict$'):
PolicyInformation(True)
with self.assertRaisesRegex(ValueError, r'^PolicyQualifier must be string, dict or x509.UserNotice$'):
PolicyInformation({'policy_identifier': '1.2.3', 'policy_qualifiers': [True]})
with self.assertRaisesRegex(
ValueError, r'^NoticeReference must be either None, a dict or an x509.NoticeReference$'):
PolicyInformation({'policy_identifier': '1.2.3', 'policy_qualifiers': [{
'notice_reference': True,
}]})