本文整理汇总了Python中cryptography.x509.UserNotice方法的典型用法代码示例。如果您正苦于以下问题:Python x509.UserNotice方法的具体用法?Python x509.UserNotice怎么用?Python x509.UserNotice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.x509
的用法示例。
在下文中一共展示了x509.UserNotice方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_policy_qualifier
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UserNotice [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 UserNotice [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 UserNotice [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 UserNotice [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: is_user_notice
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UserNotice [as 别名]
def is_user_notice(value):
return isinstance(value, x509.UserNotice)
示例6: as_text
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UserNotice [as 别名]
def as_text(self, width=76):
if self.policy_identifier is None:
text = 'Policy Identifier: %s\n' % None
else:
text = 'Policy Identifier: %s\n' % self.policy_identifier.dotted_string
if self.policy_qualifiers:
text += 'Policy Qualifiers:\n'
for qualifier in self.policy_qualifiers:
if isinstance(qualifier, str):
lines = textwrap.wrap(qualifier, initial_indent='* ', subsequent_indent=' ', width=width)
text += '%s\n' % '\n'.join(lines)
else:
text += '* UserNotice:\n'
if qualifier.explicit_text:
text += '\n'.join(textwrap.wrap(
'Explicit text: %s\n' % qualifier.explicit_text,
initial_indent=' * ', subsequent_indent=' ', width=width - 2
)) + '\n'
if qualifier.notice_reference:
text += ' * Reference:\n'
text += ' * Organiziation: %s\n' % qualifier.notice_reference.organization
text += ' * Notice Numbers: %s\n' % qualifier.notice_reference.notice_numbers
else:
text += 'No Policy Qualifiers'
return text.strip()
示例7: test_as_text
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UserNotice [as 别名]
def test_as_text(self):
self.assertEqual(self.pi1.as_text(), 'Policy Identifier: 2.5.29.32.0\n'
'Policy Qualifiers:\n* text1')
self.assertEqual(self.pi2.as_text(), 'Policy Identifier: 2.5.29.32.0\n'
'Policy Qualifiers:\n'
'* UserNotice:\n'
' * Explicit text: text2')
self.assertEqual(self.pi3.as_text(),
'Policy Identifier: 2.5.29.32.0\n'
'Policy Qualifiers:\n'
'* UserNotice:\n'
' * Reference:\n'
' * Organiziation: text3\n'
' * Notice Numbers: [1]')
self.assertEqual(self.pi4.as_text(),
'Policy Identifier: 2.5.29.32.0\n'
'Policy Qualifiers:\n'
'* text4\n'
'* UserNotice:\n'
' * Explicit text: text5\n'
' * Reference:\n'
' * Organiziation: text6\n'
' * Notice Numbers: [1, 2, 3]')
self.assertEqual(self.pi_empty.as_text(), 'Policy Identifier: None\nNo Policy Qualifiers')
self.load_all_cas()
self.load_all_certs()
for name, cert in list(self.cas.items()) + list(self.certs.items()):
try:
ext = cert.x509.extensions.get_extension_for_oid(ExtensionOID.CERTIFICATE_POLICIES).value
except x509.ExtensionNotFound:
continue
for index, policy in enumerate(ext):
pi = PolicyInformation(policy)
self.assertEqual(pi.as_text(), certs[name]['policy_texts'][index])
示例8: _encode_certificate_policies
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UserNotice [as 别名]
def _encode_certificate_policies(backend, certificate_policies):
cp = backend._lib.sk_POLICYINFO_new_null()
backend.openssl_assert(cp != backend._ffi.NULL)
cp = backend._ffi.gc(cp, backend._lib.sk_POLICYINFO_free)
for policy_info in certificate_policies:
pi = backend._lib.POLICYINFO_new()
backend.openssl_assert(pi != backend._ffi.NULL)
res = backend._lib.sk_POLICYINFO_push(cp, pi)
backend.openssl_assert(res >= 1)
oid = _txt2obj(backend, policy_info.policy_identifier.dotted_string)
pi.policyid = oid
if policy_info.policy_qualifiers:
pqis = backend._lib.sk_POLICYQUALINFO_new_null()
backend.openssl_assert(pqis != backend._ffi.NULL)
for qualifier in policy_info.policy_qualifiers:
pqi = backend._lib.POLICYQUALINFO_new()
backend.openssl_assert(pqi != backend._ffi.NULL)
res = backend._lib.sk_POLICYQUALINFO_push(pqis, pqi)
backend.openssl_assert(res >= 1)
if isinstance(qualifier, six.text_type):
pqi.pqualid = _txt2obj(
backend, x509.OID_CPS_QUALIFIER.dotted_string
)
pqi.d.cpsuri = _encode_asn1_str(
backend,
qualifier.encode("ascii"),
len(qualifier.encode("ascii"))
)
else:
assert isinstance(qualifier, x509.UserNotice)
pqi.pqualid = _txt2obj(
backend, x509.OID_CPS_USER_NOTICE.dotted_string
)
un = backend._lib.USERNOTICE_new()
backend.openssl_assert(un != backend._ffi.NULL)
pqi.d.usernotice = un
if qualifier.explicit_text:
un.exptext = _encode_asn1_utf8_str(
backend, qualifier.explicit_text
)
un.noticeref = _encode_notice_reference(
backend, qualifier.notice_reference
)
pi.qualifiers = pqis
pp = backend._ffi.new('unsigned char **')
r = backend._lib.i2d_CERTIFICATEPOLICIES(cp, pp)
backend.openssl_assert(r > 0)
pp = backend._ffi.gc(
pp, lambda pointer: backend._lib.OPENSSL_free(pointer[0])
)
return pp, r
示例9: _encode_certificate_policies
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UserNotice [as 别名]
def _encode_certificate_policies(backend, certificate_policies):
cp = backend._lib.sk_POLICYINFO_new_null()
backend.openssl_assert(cp != backend._ffi.NULL)
cp = backend._ffi.gc(cp, backend._lib.sk_POLICYINFO_free)
for policy_info in certificate_policies:
pi = backend._lib.POLICYINFO_new()
backend.openssl_assert(pi != backend._ffi.NULL)
res = backend._lib.sk_POLICYINFO_push(cp, pi)
backend.openssl_assert(res >= 1)
oid = _txt2obj(backend, policy_info.policy_identifier.dotted_string)
pi.policyid = oid
if policy_info.policy_qualifiers:
pqis = backend._lib.sk_POLICYQUALINFO_new_null()
backend.openssl_assert(pqis != backend._ffi.NULL)
for qualifier in policy_info.policy_qualifiers:
pqi = backend._lib.POLICYQUALINFO_new()
backend.openssl_assert(pqi != backend._ffi.NULL)
res = backend._lib.sk_POLICYQUALINFO_push(pqis, pqi)
backend.openssl_assert(res >= 1)
if isinstance(qualifier, six.text_type):
pqi.pqualid = _txt2obj(
backend, x509.OID_CPS_QUALIFIER.dotted_string
)
pqi.d.cpsuri = _encode_asn1_str(
backend,
qualifier.encode("ascii"),
len(qualifier.encode("ascii"))
)
else:
assert isinstance(qualifier, x509.UserNotice)
pqi.pqualid = _txt2obj(
backend, x509.OID_CPS_USER_NOTICE.dotted_string
)
un = backend._lib.USERNOTICE_new()
backend.openssl_assert(un != backend._ffi.NULL)
pqi.d.usernotice = un
if qualifier.explicit_text:
un.exptext = _encode_asn1_utf8_str(
backend, qualifier.explicit_text
)
un.noticeref = _encode_notice_reference(
backend, qualifier.notice_reference
)
pi.qualifiers = pqis
return cp
示例10: _encode_certificate_policies
# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UserNotice [as 别名]
def _encode_certificate_policies(backend, certificate_policies):
cp = backend._lib.sk_POLICYINFO_new_null()
backend.openssl_assert(cp != backend._ffi.NULL)
cp = backend._ffi.gc(cp, backend._lib.sk_POLICYINFO_free)
for policy_info in certificate_policies:
pi = backend._lib.POLICYINFO_new()
backend.openssl_assert(pi != backend._ffi.NULL)
res = backend._lib.sk_POLICYINFO_push(cp, pi)
backend.openssl_assert(res >= 1)
oid = _txt2obj(backend, policy_info.policy_identifier.dotted_string)
pi.policyid = oid
if policy_info.policy_qualifiers:
pqis = backend._lib.sk_POLICYQUALINFO_new_null()
backend.openssl_assert(pqis != backend._ffi.NULL)
for qualifier in policy_info.policy_qualifiers:
pqi = backend._lib.POLICYQUALINFO_new()
backend.openssl_assert(pqi != backend._ffi.NULL)
res = backend._lib.sk_POLICYQUALINFO_push(pqis, pqi)
backend.openssl_assert(res >= 1)
if isinstance(qualifier, six.text_type):
pqi.pqualid = _txt2obj(
backend, x509.OID_CPS_QUALIFIER.dotted_string
)
pqi.d.cpsuri = _encode_asn1_str(
backend,
qualifier.encode("ascii"),
)
else:
assert isinstance(qualifier, x509.UserNotice)
pqi.pqualid = _txt2obj(
backend, x509.OID_CPS_USER_NOTICE.dotted_string
)
un = backend._lib.USERNOTICE_new()
backend.openssl_assert(un != backend._ffi.NULL)
pqi.d.usernotice = un
if qualifier.explicit_text:
un.exptext = _encode_asn1_utf8_str(
backend, qualifier.explicit_text
)
un.noticeref = _encode_notice_reference(
backend, qualifier.notice_reference
)
pi.qualifiers = pqis
return cp