当前位置: 首页>>代码示例>>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;未经允许,请勿转载。