我们从Python开源项目中,提取了以下30个代码示例,用于说明如何使用cryptography.x509.UserNotice()。
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)
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)
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
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