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


Python general_name.IPAddress方法代碼示例

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


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

示例1: _validate_ip_name

# 需要導入模塊: from cryptography.x509 import general_name [as 別名]
# 或者: from cryptography.x509.general_name import IPAddress [as 別名]
def _validate_ip_name(self, tree):
        if any(isinstance(name, IPAddress) and not isinstance(
            name.value, (ipaddress.IPv4Network, ipaddress.IPv6Network)
        ) for name in tree):
            raise TypeError(
                "IPAddress name constraints must be an IPv4Network or"
                " IPv6Network object"
            ) 
開發者ID:DirceuSilvaLabs,項目名稱:noc-orchestrator,代碼行數:10,代碼來源:extensions.py

示例2: _extAttribDict2x509List

# 需要導入模塊: from cryptography.x509 import general_name [as 別名]
# 或者: from cryptography.x509.general_name import IPAddress [as 別名]
def _extAttribDict2x509List(extensions):
    extensions = extensions or OrderedDict()
    ext_list = []

    # SubjectAlternativeName
    values = extensions.get('subject_alternative_name')
    if values:
        if not isinstance(values, list):
            values = [values]
        general_name_values = []
        for pair in values:
            try:
                type_, value = pair.split(':')
                type_ = type_.lower()
                if type_ not in ['ip', 'dns']:
                    raise ValueError()
            except ValueError:
                raise ValueError(
                    'subject_alternative_name must be prefixed'
                    ' with type "ip" or "dns" (e.g. "ip:10.1.1.1")'
                    ' invalid value: {0!r}'.format(pair))
            if type_ == 'ip':
                value = IPAddress(ipaddress.ip_address(value))
            elif type_ == 'dns':
                value = DNSName(value)
            general_name_values.append(value)
        ext_list.append(SubjectAlternativeName(general_name_values))

    return ext_list 
開發者ID:iffy,項目名稱:humancrypto,代碼行數:31,代碼來源:pki.py

示例3: _x509Ext2Dict

# 需要導入模塊: from cryptography.x509 import general_name [as 別名]
# 或者: from cryptography.x509.general_name import IPAddress [as 別名]
def _x509Ext2Dict(extensions):
    """
    Read cryptography extensions and return a dict.
    """
    ret = {}
    for name, data in EXT_MAPPING.items():
        oid = data['oid']
        try:
            value = extensions.get_extension_for_oid(oid)
        except x509.ExtensionNotFound:
            continue

        if value:
            val = value.value

            if name == 'basic_constraints':
                val = _basicConstraints2Dict(val)
            elif name == 'subject_key_identifier':
                val = val.digest
            elif name == 'authority_key_identifier':
                issuer = [_CertificateNameHolder(x.value).attribs for x
                          in val.authority_cert_issuer]
                val = {
                    'keyid': val.key_identifier,
                    'serial': val.authority_cert_serial_number,
                    'issuer': issuer,
                }
                if len(val['issuer']) == 1:
                    val['issuer'] = val['issuer'][0]
            elif name == 'key_usage':
                tmp = {}
                for k in KEY_USAGE_ATTRS:
                    try:
                        tmp[k] = getattr(val, k, False)
                    except ValueError:
                        tmp[k] = None
                val = tmp
            elif name == 'extended_key_usage':
                tmp = {}
                for k, v in EXT_KEY_USAGE_MAPPING.items():
                    if v in val:
                        tmp[k] = True
                    else:
                        tmp[k] = False
                val = tmp
            elif name == 'subject_alternative_name':
                val = {
                    'ip': [x.exploded for x
                           in val.get_values_for_type(IPAddress)],
                    'dns': val.get_values_for_type(DNSName),
                }
            else:
                pass
            ret[name] = val
    return ret 
開發者ID:iffy,項目名稱:humancrypto,代碼行數:57,代碼來源:pki.py


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