desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
':return:
An iterator of child values'
| def __iter__(self):
| return iter(self._children)
|
'Sets the value of the object before passing to Asn1Value.__init__()
:param value:
A native Python datatype to initialize the object value with
:param default:
The default value if no value is specified
:param contents:
A byte string of the encoded contents of the value'
| def __init__(self, value=None, default=None, contents=None, **kwargs):
| Asn1Value.__init__(self, **kwargs)
try:
if (contents is not None):
self.contents = contents
elif (value is not None):
self.set(value)
elif (default is not None):
self.set(default)
except (ValueError, TypeError) as e:
args = e.args[1:]
e.args = (((e.args[0] + (u'\n while constructing %s' % type_name(self))),) + args)
raise e
|
'Sets the value of the object
:param value:
A byte string'
| def set(self, value):
| if (not isinstance(value, byte_cls)):
raise TypeError(unwrap(u'\n %s value must be a byte string, not %s\n ', type_name(self), type_name(value)))
self._native = value
self.contents = value
self._header = None
if (self._trailer != ''):
self._trailer = ''
|
'Encodes the value using DER
:param force:
If the encoded contents already exist, clear them and regenerate
to ensure they are in DER format instead of BER format
:return:
A byte string of the DER-encoded value'
| def dump(self, force=False):
| if force:
native = self.native
self.contents = None
self.set(native)
return Asn1Value.dump(self)
|
':param other:
The other Primitive to compare to
:return:
A boolean'
| def __eq__(self, other):
| if (not isinstance(other, Primitive)):
return False
if (self.contents != other.contents):
return False
if (self.__class__.tag != other.__class__.tag):
return False
if ((self.__class__ == other.__class__) and (self.contents == other.contents)):
return True
self_bases = ((set(self.__class__.__bases__) | set([self.__class__])) - set([Asn1Value, Primitive, ValueMap]))
other_bases = ((set(other.__class__.__bases__) | set([other.__class__])) - set([Asn1Value, Primitive, ValueMap]))
if (self_bases | other_bases):
return (self.contents == other.contents)
if ((self.tag_type is not None) or (other.tag_type is not None)):
return (self.untag().dump() == other.untag().dump())
return (self.dump() == other.dump())
|
'Sets the value of the string
:param value:
A unicode string'
| def set(self, value):
| if (not isinstance(value, str_cls)):
raise TypeError(unwrap(u'\n %s value must be a unicode string, not %s\n ', type_name(self), type_name(value)))
self._unicode = value
self.contents = value.encode(self._encoding)
self._header = None
if self._indefinite:
self._indefinite = False
self.method = 0
if (self._trailer != ''):
self._trailer = ''
|
':return:
A unicode string'
| def __unicode__(self):
| if (self.contents is None):
return u''
if (self._unicode is None):
self._unicode = self._merge_chunks().decode(self._encoding)
return self._unicode
|
'Copies the contents of another AbstractString object to itself
:param object:
Another instance of the same class
:param copy_func:
An reference of copy.copy() or copy.deepcopy() to use when copying
lists, dicts and objects'
| def _copy(self, other, copy_func):
| super(AbstractString, self)._copy(other, copy_func)
self._unicode = other._unicode
|
'The a native Python datatype representation of this value
:return:
A unicode string or None'
| @property
def native(self):
| if (self.contents is None):
return None
return self.__unicode__()
|
'Sets the value of the object
:param value:
True, False or another value that works with bool()'
| def set(self, value):
| self._native = bool(value)
self.contents = ('\x00' if (not value) else '\xff')
self._header = None
if (self._trailer != ''):
self._trailer = ''
|
':return:
True or False'
| def __nonzero__(self):
| return self.__bool__()
|
':return:
True or False'
| def __bool__(self):
| return (self.contents != '\x00')
|
'The a native Python datatype representation of this value
:return:
True, False or None'
| @property
def native(self):
| if (self.contents is None):
return None
if (self._native is None):
self._native = self.__bool__()
return self._native
|
'Sets the value of the object
:param value:
An integer, or a unicode string if _map is set
:raises:
ValueError - when an invalid value is passed'
| def set(self, value):
| if isinstance(value, str_cls):
if (self._map is None):
raise ValueError(unwrap(u'\n %s value is a unicode string, but no _map provided\n ', type_name(self)))
if (value not in self._reverse_map):
raise ValueError(unwrap(u'\n %s value, %s, is not present in the _map\n ', type_name(self), value))
value = self._reverse_map[value]
elif (not isinstance(value, int_types)):
raise TypeError(unwrap(u'\n %s value must be an integer or unicode string when a name_map\n is provided, not %s\n ', type_name(self), type_name(value)))
self._native = (self._map[value] if (self._map and (value in self._map)) else value)
self.contents = int_to_bytes(value, signed=True)
self._header = None
if (self._trailer != ''):
self._trailer = ''
|
':return:
An integer'
| def __int__(self):
| return int_from_bytes(self.contents, signed=True)
|
'The a native Python datatype representation of this value
:return:
An integer or None'
| @property
def native(self):
| if (self.contents is None):
return None
if (self._native is None):
self._native = self.__int__()
if ((self._map is not None) and (self._native in self._map)):
self._native = self._map[self._native]
return self._native
|
'Generates _reverse_map from _map'
| def _setup(self):
| ValueMap._setup(self)
cls = self.__class__
if (cls._map is not None):
cls._size = (max(self._map.keys()) + 1)
|
'Sets the value of the object
:param value:
An integer or a tuple of integers 0 and 1
:raises:
ValueError - when an invalid value is passed'
| def set(self, value):
| if isinstance(value, set):
if (self._map is None):
raise ValueError(unwrap(u'\n %s._map has not been defined\n ', type_name(self)))
bits = ([0] * self._size)
self._native = value
for index in range(0, self._size):
key = self._map.get(index)
if (key is None):
continue
if (key in value):
bits[index] = 1
value = u''.join(map(str_cls, bits))
elif (value.__class__ == tuple):
if (self._map is None):
self._native = value
else:
self._native = set()
for (index, bit) in enumerate(value):
if bit:
name = self._map.get(index, index)
self._native.add(name)
value = u''.join(map(str_cls, value))
else:
raise TypeError(unwrap(u'\n %s value must be a tuple of ones and zeros or a set of unicode\n strings, not %s\n ', type_name(self), type_name(value)))
self._chunk = None
if (self._map is not None):
if (len(value) > self._size):
raise ValueError(unwrap(u'\n %s value must be at most %s bits long, specified was %s long\n ', type_name(self), self._size, len(value)))
value = value.rstrip(u'0')
size = len(value)
size_mod = (size % 8)
extra_bits = 0
if (size_mod != 0):
extra_bits = (8 - size_mod)
value += (u'0' * extra_bits)
size_in_bytes = int(math.ceil((size / 8)))
if extra_bits:
extra_bits_byte = int_to_bytes(extra_bits)
else:
extra_bits_byte = '\x00'
if (value == u''):
value_bytes = ''
else:
value_bytes = int_to_bytes(int(value, 2))
if (len(value_bytes) != size_in_bytes):
value_bytes = (('\x00' * (size_in_bytes - len(value_bytes))) + value_bytes)
self.contents = (extra_bits_byte + value_bytes)
self._header = None
if self._indefinite:
self._indefinite = False
self.method = 0
if (self._trailer != ''):
self._trailer = ''
|
'Retrieves a boolean version of one of the bits based on a name from the
_map
:param key:
The unicode string of one of the bit names
:raises:
ValueError - when _map is not set or the key name is invalid
:return:
A boolean if the bit is set'
| def __getitem__(self, key):
| is_int = isinstance(key, int_types)
if (not is_int):
if (not isinstance(self._map, dict)):
raise ValueError(unwrap(u'\n %s._map has not been defined\n ', type_name(self)))
if (key not in self._reverse_map):
raise ValueError(unwrap(u'\n %s._map does not contain an entry for "%s"\n ', type_name(self), key))
if (self._native is None):
self.native
if (self._map is None):
if (len(self._native) >= (key + 1)):
return bool(self._native[key])
return False
if is_int:
key = self._map.get(key, key)
return (key in self._native)
|
'Sets one of the bits based on a name from the _map
:param key:
The unicode string of one of the bit names
:param value:
A boolean value
:raises:
ValueError - when _map is not set or the key name is invalid'
| def __setitem__(self, key, value):
| is_int = isinstance(key, int_types)
if (not is_int):
if (self._map is None):
raise ValueError(unwrap(u'\n %s._map has not been defined\n ', type_name(self)))
if (key not in self._reverse_map):
raise ValueError(unwrap(u'\n %s._map does not contain an entry for "%s"\n ', type_name(self), key))
if (self._native is None):
self.native
if (self._map is None):
new_native = list(self._native)
max_key = (len(new_native) - 1)
if (key > max_key):
new_native.extend(([0] * (key - max_key)))
new_native[key] = (1 if value else 0)
self._native = tuple(new_native)
else:
if is_int:
key = self._map.get(key, key)
if value:
if (key not in self._native):
self._native.add(key)
elif (key in self._native):
self._native.remove(key)
self.set(self._native)
|
'Allows reconstructing indefinite length values
:return:
A tuple of integers'
| def _as_chunk(self):
| extra_bits = int_from_bytes(self.contents[0:1])
bit_string = u'{0:b}'.format(int_from_bytes(self.contents[1:]))
byte_len = len(self.contents[1:])
bit_len = len(bit_string)
mod_bit_len = (bit_len % 8)
if (mod_bit_len != 0):
bit_string = ((u'0' * (8 - mod_bit_len)) + bit_string)
bit_len = len(bit_string)
if ((bit_len // 8) < byte_len):
missing_bytes = (byte_len - (bit_len // 8))
bit_string = ((u'0' * (8 * missing_bytes)) + bit_string)
if (extra_bits > 0):
bit_string = bit_string[0:(0 - extra_bits)]
return tuple(map(int, tuple(bit_string)))
|
'The a native Python datatype representation of this value
:return:
If a _map is set, a set of names, or if no _map is set, a tuple of
integers 1 and 0. None if no value.'
| @property
def native(self):
| if (self.contents is None):
if (self._map is None):
self.set(())
else:
self.set(set())
if (self._native is None):
bits = self._merge_chunks()
if self._map:
self._native = set()
for (index, bit) in enumerate(bits):
if bit:
name = self._map.get(index, index)
self._native.add(name)
else:
self._native = bits
return self._native
|
'Sets the value of the object
:param value:
A byte string
:raises:
ValueError - when an invalid value is passed'
| def set(self, value):
| if (not isinstance(value, byte_cls)):
raise TypeError(unwrap(u'\n %s value must be a byte string, not %s\n ', type_name(self), type_name(value)))
self._bytes = value
self.contents = ('\x00' + value)
self._header = None
if self._indefinite:
self._indefinite = False
self.method = 0
if (self._trailer != ''):
self._trailer = ''
|
':return:
A byte string'
| def __bytes__(self):
| if (self.contents is None):
return ''
if (self._bytes is None):
self._bytes = self._merge_chunks()
return self._bytes
|
'Copies the contents of another OctetBitString object to itself
:param object:
Another instance of the same class
:param copy_func:
An reference of copy.copy() or copy.deepcopy() to use when copying
lists, dicts and objects'
| def _copy(self, other, copy_func):
| super(OctetBitString, self)._copy(other, copy_func)
self._bytes = other._bytes
|
'The a native Python datatype representation of this value
:return:
A byte string or None'
| @property
def native(self):
| if (self.contents is None):
return None
return self.__bytes__()
|
'Sets the value of the object
:param value:
An integer
:raises:
ValueError - when an invalid value is passed'
| def set(self, value):
| if (not isinstance(value, int_types)):
raise TypeError(unwrap(u'\n %s value must be an integer, not %s\n ', type_name(self), type_name(value)))
self._native = value
self.contents = ('\x00' + int_to_bytes(value, signed=True))
self._header = None
if self._indefinite:
self._indefinite = False
self.method = 0
if (self._trailer != ''):
self._trailer = ''
|
':return:
A unicode string of "rsassa_pkcs1v15", "rsassa_pss", "dsa" or
"ecdsa"'
| @property
def signature_algo(self):
| algorithm = self[u'algorithm'].native
algo_map = {u'md2_rsa': u'rsassa_pkcs1v15', u'md5_rsa': u'rsassa_pkcs1v15', u'sha1_rsa': u'rsassa_pkcs1v15', u'sha224_rsa': u'rsassa_pkcs1v15', u'sha256_rsa': u'rsassa_pkcs1v15', u'sha384_rsa': u'rsassa_pkcs1v15', u'sha512_rsa': u'rsassa_pkcs1v15', u'rsassa_pkcs1v15': u'rsassa_pkcs1v15', u'rsassa_pss': u'rsassa_pss', u'sha1_dsa': u'dsa', u'sha224_dsa': u'dsa', u'sha256_dsa': u'dsa', u'dsa': u'dsa', u'sha1_ecdsa': u'ecdsa', u'sha224_ecdsa': u'ecdsa', u'sha256_ecdsa': u'ecdsa', u'sha384_ecdsa': u'ecdsa', u'sha512_ecdsa': u'ecdsa', u'ecdsa': u'ecdsa'}
if (algorithm in algo_map):
return algo_map[algorithm]
raise ValueError(unwrap(u'\n Signature algorithm not known for %s\n ', algorithm))
|
':return:
A unicode string of "md2", "md5", "sha1", "sha224", "sha256",
"sha384", "sha512", "sha512_224", "sha512_256"'
| @property
def hash_algo(self):
| algorithm = self[u'algorithm'].native
algo_map = {u'md2_rsa': u'md2', u'md5_rsa': u'md5', u'sha1_rsa': u'sha1', u'sha224_rsa': u'sha224', u'sha256_rsa': u'sha256', u'sha384_rsa': u'sha384', u'sha512_rsa': u'sha512', u'sha1_dsa': u'sha1', u'sha224_dsa': u'sha224', u'sha256_dsa': u'sha256', u'sha1_ecdsa': u'sha1', u'sha224_ecdsa': u'sha224', u'sha256_ecdsa': u'sha256', u'sha384_ecdsa': u'sha384', u'sha512_ecdsa': u'sha512'}
if (algorithm in algo_map):
return algo_map[algorithm]
if (algorithm == u'rsassa_pss'):
return self[u'parameters'][u'hash_algorithm'][u'algorithm'].native
raise ValueError(unwrap(u'\n Hash algorithm not known for %s\n ', algorithm))
|
'Reads a signature from a byte string encoding accordint to IEEE P1363,
which is used by Microsoft\'s BCryptSignHash() function.
:param data:
A byte string from BCryptSignHash()
:return:
A DSASignature object'
| @classmethod
def from_p1363(cls, data):
| r = int_from_bytes(data[0:(len(data) // 2)])
s = int_from_bytes(data[(len(data) // 2):])
return cls({u'r': r, u's': s})
|
'Dumps a signature to a byte string compatible with Microsoft\'s
BCryptVerifySignature() function.
:return:
A byte string compatible with BCryptVerifySignature()'
| def to_p1363(self):
| r_bytes = int_to_bytes(self[u'r'].native)
s_bytes = int_to_bytes(self[u's'].native)
int_byte_length = max(len(r_bytes), len(s_bytes))
r_bytes = fill_width(r_bytes, int_byte_length)
s_bytes = fill_width(s_bytes, int_byte_length)
return (r_bytes + s_bytes)
|
'Returns the name of the key derivation function to use.
:return:
A unicode from of one of the following: "pbkdf1", "pbkdf2",
"pkcs12_kdf"'
| @property
def kdf(self):
| encryption_algo = self[u'algorithm'].native
if (encryption_algo == u'pbes2'):
return self[u'parameters'][u'key_derivation_func'][u'algorithm'].native
if (encryption_algo.find(u'.') == (-1)):
if (encryption_algo.find(u'_') != (-1)):
(encryption_algo, _) = encryption_algo.split(u'_', 1)
if (encryption_algo == u'pbes1'):
return u'pbkdf1'
if (encryption_algo == u'pkcs12'):
return u'pkcs12_kdf'
raise ValueError(unwrap(u'\n Encryption algorithm "%s" does not have a registered key\n derivation function\n ', encryption_algo))
raise ValueError(unwrap(u'\n Unrecognized encryption algorithm "%s", can not determine key\n derivation function\n ', encryption_algo))
|
'Returns the HMAC algorithm to use with the KDF.
:return:
A unicode string of one of the following: "md2", "md5", "sha1",
"sha224", "sha256", "sha384", "sha512"'
| @property
def kdf_hmac(self):
| encryption_algo = self[u'algorithm'].native
if (encryption_algo == u'pbes2'):
return self[u'parameters'][u'key_derivation_func'][u'parameters'][u'prf'][u'algorithm'].native
if (encryption_algo.find(u'.') == (-1)):
if (encryption_algo.find(u'_') != (-1)):
(_, hmac_algo, _) = encryption_algo.split(u'_', 2)
return hmac_algo
raise ValueError(unwrap(u'\n Encryption algorithm "%s" does not have a registered key\n derivation function\n ', encryption_algo))
raise ValueError(unwrap(u'\n Unrecognized encryption algorithm "%s", can not determine key\n derivation hmac algorithm\n ', encryption_algo))
|
'Returns the byte string to use as the salt for the KDF.
:return:
A byte string'
| @property
def kdf_salt(self):
| encryption_algo = self[u'algorithm'].native
if (encryption_algo == u'pbes2'):
salt = self[u'parameters'][u'key_derivation_func'][u'parameters'][u'salt']
if (salt.name == u'other_source'):
raise ValueError(unwrap(u'\n Can not determine key derivation salt - the\n reserved-for-future-use other source salt choice was\n specified in the PBKDF2 params structure\n '))
return salt.native
if (encryption_algo.find(u'.') == (-1)):
if (encryption_algo.find(u'_') != (-1)):
return self[u'parameters'][u'salt'].native
raise ValueError(unwrap(u'\n Encryption algorithm "%s" does not have a registered key\n derivation function\n ', encryption_algo))
raise ValueError(unwrap(u'\n Unrecognized encryption algorithm "%s", can not determine key\n derivation salt\n ', encryption_algo))
|
'Returns the number of iterations that should be run via the KDF.
:return:
An integer'
| @property
def kdf_iterations(self):
| encryption_algo = self[u'algorithm'].native
if (encryption_algo == u'pbes2'):
return self[u'parameters'][u'key_derivation_func'][u'parameters'][u'iteration_count'].native
if (encryption_algo.find(u'.') == (-1)):
if (encryption_algo.find(u'_') != (-1)):
return self[u'parameters'][u'iterations'].native
raise ValueError(unwrap(u'\n Encryption algorithm "%s" does not have a registered key\n derivation function\n ', encryption_algo))
raise ValueError(unwrap(u'\n Unrecognized encryption algorithm "%s", can not determine key\n derivation iterations\n ', encryption_algo))
|
'Returns the key length to pass to the cipher/kdf. The PKCS#5 spec does
not specify a way to store the RC5 key length, however this tends not
to be a problem since OpenSSL does not support RC5 in PKCS#8 and OS X
does not provide an RC5 cipher for use in the Security Transforms
library.
:raises:
ValueError - when the key length can not be determined
:return:
An integer representing the length in bytes'
| @property
def key_length(self):
| encryption_algo = self[u'algorithm'].native
if (encryption_algo[0:3] == u'aes'):
return {u'aes128_': 16, u'aes192_': 24, u'aes256_': 32}[encryption_algo[0:7]]
cipher_lengths = {u'des': 8, u'tripledes_3key': 24}
if (encryption_algo in cipher_lengths):
return cipher_lengths[encryption_algo]
if (encryption_algo == u'rc2'):
rc2_params = self[u'parameters'].parsed[u'encryption_scheme'][u'parameters'].parsed
rc2_parameter_version = rc2_params[u'rc2_parameter_version'].native
encoded_key_bits_map = {160: 5, 120: 8, 58: 16}
if (rc2_parameter_version in encoded_key_bits_map):
return encoded_key_bits_map[rc2_parameter_version]
if (rc2_parameter_version >= 256):
return rc2_parameter_version
if (rc2_parameter_version is None):
return 4
raise ValueError(unwrap(u'\n Invalid RC2 parameter version found in EncryptionAlgorithm\n parameters\n '))
if (encryption_algo == u'pbes2'):
key_length = self[u'parameters'][u'key_derivation_func'][u'parameters'][u'key_length'].native
if (key_length is not None):
return key_length
return self[u'parameters'][u'encryption_scheme'].key_length
if (encryption_algo.find(u'.') == (-1)):
return {u'pbes1_md2_des': 8, u'pbes1_md5_des': 8, u'pbes1_md2_rc2': 8, u'pbes1_md5_rc2': 8, u'pbes1_sha1_des': 8, u'pbes1_sha1_rc2': 8, u'pkcs12_sha1_rc4_128': 16, u'pkcs12_sha1_rc4_40': 5, u'pkcs12_sha1_tripledes_3key': 24, u'pkcs12_sha1_tripledes_2key': 16, u'pkcs12_sha1_rc2_128': 16, u'pkcs12_sha1_rc2_40': 5}[encryption_algo]
raise ValueError(unwrap(u'\n Unrecognized encryption algorithm "%s"\n ', encryption_algo))
|
'Returns the name of the encryption mode to use.
:return:
A unicode string from one of the following: "cbc", "ecb", "ofb",
"cfb", "wrap", "gcm", "ccm", "wrap_pad"'
| @property
def encryption_mode(self):
| encryption_algo = self[u'algorithm'].native
if (encryption_algo[0:7] in set([u'aes128_', u'aes192_', u'aes256_'])):
return encryption_algo[7:]
if (encryption_algo[0:6] == u'pbes1_'):
return u'cbc'
if (encryption_algo[0:7] == u'pkcs12_'):
return u'cbc'
if (encryption_algo in set([u'des', u'tripledes_3key', u'rc2', u'rc5'])):
return u'cbc'
if (encryption_algo == u'pbes2'):
return self[u'parameters'][u'encryption_scheme'].encryption_mode
raise ValueError(unwrap(u'\n Unrecognized encryption algorithm "%s"\n ', encryption_algo))
|
'Returns the name of the symmetric encryption cipher to use. The key
length can be retrieved via the .key_length property to disabiguate
between different variations of TripleDES, AES, and the RC* ciphers.
:return:
A unicode string from one of the following: "rc2", "rc5", "des",
"tripledes", "aes"'
| @property
def encryption_cipher(self):
| encryption_algo = self[u'algorithm'].native
if (encryption_algo[0:7] in set([u'aes128_', u'aes192_', u'aes256_'])):
return u'aes'
if (encryption_algo in set([u'des', u'rc2', u'rc5'])):
return encryption_algo
if (encryption_algo == u'tripledes_3key'):
return u'tripledes'
if (encryption_algo == u'pbes2'):
return self[u'parameters'][u'encryption_scheme'].encryption_cipher
if (encryption_algo.find(u'.') == (-1)):
return {u'pbes1_md2_des': u'des', u'pbes1_md5_des': u'des', u'pbes1_md2_rc2': u'rc2', u'pbes1_md5_rc2': u'rc2', u'pbes1_sha1_des': u'des', u'pbes1_sha1_rc2': u'rc2', u'pkcs12_sha1_rc4_128': u'rc4', u'pkcs12_sha1_rc4_40': u'rc4', u'pkcs12_sha1_tripledes_3key': u'tripledes', u'pkcs12_sha1_tripledes_2key': u'tripledes', u'pkcs12_sha1_rc2_128': u'rc2', u'pkcs12_sha1_rc2_40': u'rc2'}[encryption_algo]
raise ValueError(unwrap(u'\n Unrecognized encryption algorithm "%s"\n ', encryption_algo))
|
'Returns the block size of the encryption cipher, in bytes.
:return:
An integer that is the block size in bytes'
| @property
def encryption_block_size(self):
| encryption_algo = self[u'algorithm'].native
if (encryption_algo[0:7] in set([u'aes128_', u'aes192_', u'aes256_'])):
return 16
cipher_map = {u'des': 8, u'tripledes_3key': 8, u'rc2': 8}
if (encryption_algo in cipher_map):
return cipher_map[encryption_algo]
if (encryption_algo == u'rc5'):
return (self[u'parameters'].parsed[u'block_size_in_bits'].native / 8)
if (encryption_algo == u'pbes2'):
return self[u'parameters'][u'encryption_scheme'].encryption_block_size
if (encryption_algo.find(u'.') == (-1)):
return {u'pbes1_md2_des': 8, u'pbes1_md5_des': 8, u'pbes1_md2_rc2': 8, u'pbes1_md5_rc2': 8, u'pbes1_sha1_des': 8, u'pbes1_sha1_rc2': 8, u'pkcs12_sha1_rc4_128': 0, u'pkcs12_sha1_rc4_40': 0, u'pkcs12_sha1_tripledes_3key': 8, u'pkcs12_sha1_tripledes_2key': 8, u'pkcs12_sha1_rc2_128': 8, u'pkcs12_sha1_rc2_40': 8}[encryption_algo]
raise ValueError(unwrap(u'\n Unrecognized encryption algorithm "%s"\n ', encryption_algo))
|
'Returns the byte string of the initialization vector for the encryption
scheme. Only the PBES2 stores the IV in the params. For PBES1, the IV
is derived from the KDF and this property will return None.
:return:
A byte string or None'
| @property
def encryption_iv(self):
| encryption_algo = self[u'algorithm'].native
if (encryption_algo in set([u'rc2', u'rc5'])):
return self[u'parameters'].parsed[u'iv'].native
octet_string_iv_oids = set([u'des', u'tripledes_3key', u'aes128_cbc', u'aes192_cbc', u'aes256_cbc', u'aes128_ofb', u'aes192_ofb', u'aes256_ofb'])
if (encryption_algo in octet_string_iv_oids):
return self[u'parameters'].native
if (encryption_algo == u'pbes2'):
return self[u'parameters'][u'encryption_scheme'].encryption_iv
if (encryption_algo.find(u'.') == (-1)):
return None
raise ValueError(unwrap(u'\n Unrecognized encryption algorithm "%s"\n ', encryption_algo))
|
':param year:
The integer 0
:param month:
An integer from 1 to 12
:param day:
An integer from 1 to 31'
| def __init__(self, year, month, day):
| if (year != 0):
raise ValueError(u'year must be 0')
if ((month < 1) or (month > 12)):
raise ValueError(u'month is out of range')
if ((day < 0) or (day > _DAYS_PER_MONTH_YEAR_0[month])):
raise ValueError(u'day is out of range')
self.year = year
self.month = month
self.day = day
|
'Performs strftime(), always returning a unicode string
:param format:
A strftime() format string
:return:
A unicode string of the formatted date'
| def _format(self, format):
| format = format.replace(u'%Y', u'0000')
temp = date(2000, self.month, self.day)
if (u'%c' in format):
c_out = temp.strftime(u'%c')
c_out = c_out.replace(u'2000', u'0000')
c_out = c_out.replace(u'%', u'%%')
format = format.replace(u'%c', c_out)
if (u'%x' in format):
x_out = temp.strftime(u'%x')
x_out = x_out.replace(u'2000', u'0000')
x_out = x_out.replace(u'%', u'%%')
format = format.replace(u'%x', x_out)
return temp.strftime(format)
|
'Formats the date as %Y-%m-%d
:return:
The date formatted to %Y-%m-%d as a unicode string in Python 3
and a byte string in Python 2'
| def isoformat(self):
| return self.strftime(u'0000-%m-%d')
|
'Formats the date using strftime()
:param format:
The strftime() format string
:return:
The formatted date as a unicode string in Python 3 and a byte
string in Python 2'
| def strftime(self, format):
| output = self._format(format)
if py2:
return output.encode(u'utf-8')
return output
|
'Returns a new datetime.date or asn1crypto.util.extended_date
object with the specified components replaced
:return:
A datetime.date or asn1crypto.util.extended_date object'
| def replace(self, year=None, month=None, day=None):
| if (year is None):
year = self.year
if (month is None):
month = self.month
if (day is None):
day = self.day
if (year > 0):
cls = date
else:
cls = extended_date
return cls(year, month, day)
|
':param year:
The integer 0
:param month:
An integer from 1 to 12
:param day:
An integer from 1 to 31
:param hour:
An integer from 0 to 23
:param minute:
An integer from 0 to 59
:param second:
An integer from 0 to 59
:param microsecond:
An integer from 0 to 999999'
| def __init__(self, year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None):
| if (year != 0):
raise ValueError(u'year must be 0')
if ((month < 1) or (month > 12)):
raise ValueError(u'month is out of range')
if ((day < 0) or (day > _DAYS_PER_MONTH_YEAR_0[month])):
raise ValueError(u'day is out of range')
if ((hour < 0) or (hour > 23)):
raise ValueError(u'hour is out of range')
if ((minute < 0) or (minute > 59)):
raise ValueError(u'minute is out of range')
if ((second < 0) or (second > 59)):
raise ValueError(u'second is out of range')
if ((microsecond < 0) or (microsecond > 999999)):
raise ValueError(u'microsecond is out of range')
self.year = year
self.month = month
self.day = day
self.hour = hour
self.minute = minute
self.second = second
self.microsecond = microsecond
self.tzinfo = tzinfo
|
':return:
An asn1crypto.util.extended_date of the date'
| def date(self):
| return extended_date(self.year, self.month, self.day)
|
':return:
A datetime.time object of the time'
| def time(self):
| return time(self.hour, self.minute, self.second, self.microsecond, self.tzinfo)
|
':return:
None or a datetime.timedelta() of the offset from UTC'
| def utcoffset(self):
| if (self.tzinfo is None):
return None
return self.tzinfo.utcoffset(self.replace(year=2000))
|
':return:
None or a datetime.timedelta() of the daylight savings time offset'
| def dst(self):
| if (self.tzinfo is None):
return None
return self.tzinfo.dst(self.replace(year=2000))
|
':return:
None or the name of the timezone as a unicode string in Python 3
and a byte string in Python 2'
| def tzname(self):
| if (self.tzinfo is None):
return None
return self.tzinfo.tzname(self.replace(year=2000))
|
'Performs strftime(), always returning a unicode string
:param format:
A strftime() format string
:return:
A unicode string of the formatted datetime'
| def _format(self, format):
| format = format.replace(u'%Y', u'0000')
temp = datetime(2000, self.month, self.day, self.hour, self.minute, self.second, self.microsecond, self.tzinfo)
if (u'%c' in format):
c_out = temp.strftime(u'%c')
c_out = c_out.replace(u'2000', u'0000')
c_out = c_out.replace(u'%', u'%%')
format = format.replace(u'%c', c_out)
if (u'%x' in format):
x_out = temp.strftime(u'%x')
x_out = x_out.replace(u'2000', u'0000')
x_out = x_out.replace(u'%', u'%%')
format = format.replace(u'%x', x_out)
return temp.strftime(format)
|
'Formats the date as "%Y-%m-%d %H:%M:%S" with the sep param between the
date and time portions
:param set:
A single character of the separator to place between the date and
time
:return:
The formatted datetime as a unicode string in Python 3 and a byte
string in Python 2'
| def isoformat(self, sep=u'T'):
| if (self.microsecond == 0):
return self.strftime((u'0000-%%m-%%d%s%%H:%%M:%%S' % sep))
return self.strftime((u'0000-%%m-%%d%s%%H:%%M:%%S.%%f' % sep))
|
'Formats the date using strftime()
:param format:
The strftime() format string
:return:
The formatted date as a unicode string in Python 3 and a byte
string in Python 2'
| def strftime(self, format):
| output = self._format(format)
if py2:
return output.encode(u'utf-8')
return output
|
'Returns a new datetime.datetime or asn1crypto.util.extended_datetime
object with the specified components replaced
:return:
A datetime.datetime or asn1crypto.util.extended_datetime object'
| def replace(self, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, tzinfo=None):
| if (year is None):
year = self.year
if (month is None):
month = self.month
if (day is None):
day = self.day
if (hour is None):
hour = self.hour
if (minute is None):
minute = self.minute
if (second is None):
second = self.second
if (microsecond is None):
microsecond = self.microsecond
if (tzinfo is None):
tzinfo = self.tzinfo
if (year > 0):
cls = datetime
else:
cls = extended_datetime
return cls(year, month, day, hour, minute, second, microsecond, tzinfo)
|
'Raises a TypeError about the other object not being suitable for
comparison
:param other:
The object being compared to'
| def _comparison_error(self, other):
| raise TypeError(unwrap(u'\n An asn1crypto.util.extended_datetime object can only be compared to\n an asn1crypto.util.extended_datetime or datetime.datetime object,\n not %s\n ', type_name(other)))
|
'Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.2
:param other:
Another DNSName object
:return:
A boolean'
| def __eq__(self, other):
| if (not isinstance(other, DNSName)):
return False
return (self.__unicode__().lower() == other.__unicode__().lower())
|
'Sets the value of the DNS name
:param value:
A unicode string'
| def set(self, value):
| if (not isinstance(value, str_cls)):
raise TypeError(unwrap(u'\n %s value must be a unicode string, not %s\n ', type_name(self), type_name(value)))
if value.startswith(u'.'):
encoded_value = ('.' + value[1:].encode(self._encoding))
else:
encoded_value = value.encode(self._encoding)
self._unicode = value
self.contents = encoded_value
self._header = None
if (self._trailer != ''):
self._trailer = ''
|
'Sets the value of the string
:param value:
A unicode string'
| def set(self, value):
| if (not isinstance(value, str_cls)):
raise TypeError(unwrap(u'\n %s value must be a unicode string, not %s\n ', type_name(self), type_name(value)))
self._unicode = value
self.contents = iri_to_uri(value)
self._header = None
if (self._trailer != ''):
self._trailer = ''
|
'Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.4
:param other:
Another URI object
:return:
A boolean'
| def __eq__(self, other):
| if (not isinstance(other, URI)):
return False
return (iri_to_uri(self.native) == iri_to_uri(other.native))
|
':return:
A unicode string'
| def __unicode__(self):
| if (self.contents is None):
return u''
if (self._unicode is None):
self._unicode = uri_to_iri(self._merge_chunks())
return self._unicode
|
':return:
A byte string of the DER-encoded contents of the sequence'
| @property
def contents(self):
| return self._contents
|
':param value:
A byte string of the DER-encoded contents of the sequence'
| @contents.setter
def contents(self, value):
| self._normalized = False
self._contents = value
|
'Sets the value of the string
:param value:
A unicode string'
| def set(self, value):
| if (not isinstance(value, str_cls)):
raise TypeError(unwrap(u'\n %s value must be a unicode string, not %s\n ', type_name(self), type_name(value)))
if (value.find(u'@') != (-1)):
(mailbox, hostname) = value.rsplit(u'@', 1)
encoded_value = ((mailbox.encode(u'ascii') + '@') + hostname.encode(u'idna'))
else:
encoded_value = value.encode(u'ascii')
self._normalized = True
self._unicode = value
self.contents = encoded_value
self._header = None
if (self._trailer != ''):
self._trailer = ''
|
':return:
A unicode string'
| def __unicode__(self):
| if (self._unicode is None):
contents = self._merge_chunks()
if (contents.find('@') == (-1)):
self._unicode = contents.decode(u'ascii')
else:
(mailbox, hostname) = contents.rsplit('@', 1)
self._unicode = ((mailbox.decode(u'ascii') + u'@') + hostname.decode(u'idna'))
return self._unicode
|
'Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.5
:param other:
Another EmailAddress object
:return:
A boolean'
| def __eq__(self, other):
| if (not isinstance(other, EmailAddress)):
return False
if (not self._normalized):
self.set(self.native)
if (not other._normalized):
other.set(other.native)
if ((self._contents.find('@') == (-1)) or (other._contents.find('@') == (-1))):
return (self._contents == other._contents)
(other_mailbox, other_hostname) = other._contents.rsplit('@', 1)
(mailbox, hostname) = self._contents.rsplit('@', 1)
if (mailbox != other_mailbox):
return False
if (hostname.lower() != other_hostname.lower()):
return False
return True
|
'This method is not applicable to IP addresses'
| def parse(self, spec=None, spec_params=None):
| raise ValueError(unwrap(u'\n IP address values can not be parsed\n '))
|
'Sets the value of the object
:param value:
A unicode string containing an IPv4 address, IPv4 address with CIDR,
an IPv6 address or IPv6 address with CIDR'
| def set(self, value):
| if (not isinstance(value, str_cls)):
raise TypeError(unwrap(u'\n %s value must be a unicode string, not %s\n ', type_name(self), type_name(value)))
original_value = value
has_cidr = (value.find(u'/') != (-1))
cidr = 0
if has_cidr:
parts = value.split(u'/', 1)
value = parts[0]
cidr = int(parts[1])
if (cidr < 0):
raise ValueError(unwrap(u'\n %s value contains a CIDR range less than 0\n ', type_name(self)))
if (value.find(u':') != (-1)):
family = socket.AF_INET6
if (cidr > 128):
raise ValueError(unwrap(u'\n %s value contains a CIDR range bigger than 128, the maximum\n value for an IPv6 address\n ', type_name(self)))
cidr_size = 128
else:
family = socket.AF_INET
if (cidr > 32):
raise ValueError(unwrap(u'\n %s value contains a CIDR range bigger than 32, the maximum\n value for an IPv4 address\n ', type_name(self)))
cidr_size = 32
cidr_bytes = ''
if has_cidr:
cidr_mask = (u'1' * cidr)
cidr_mask += (u'0' * (cidr_size - len(cidr_mask)))
cidr_bytes = int_to_bytes(int(cidr_mask, 2))
cidr_bytes = (('\x00' * ((cidr_size // 8) - len(cidr_bytes))) + cidr_bytes)
self._native = original_value
self.contents = (inet_pton(family, value) + cidr_bytes)
self._bytes = self.contents
self._header = None
if (self._trailer != ''):
self._trailer = ''
|
'The a native Python datatype representation of this value
:return:
A unicode string or None'
| @property
def native(self):
| if (self.contents is None):
return None
if (self._native is None):
byte_string = self.__bytes__()
byte_len = len(byte_string)
cidr_int = None
if (byte_len in set([32, 16])):
value = inet_ntop(socket.AF_INET6, byte_string[0:16])
if (byte_len > 16):
cidr_int = int_from_bytes(byte_string[16:])
elif (byte_len in set([8, 4])):
value = inet_ntop(socket.AF_INET, byte_string[0:4])
if (byte_len > 4):
cidr_int = int_from_bytes(byte_string[4:])
if (cidr_int is not None):
cidr_bits = u'{0:b}'.format(cidr_int)
cidr = len(cidr_bits.rstrip(u'0'))
value = ((value + u'/') + str_cls(cidr))
self._native = value
return self._native
|
':param other:
Another IPAddress object
:return:
A boolean'
| def __eq__(self, other):
| if (not isinstance(other, IPAddress)):
return False
return (self.__bytes__() == other.__bytes__())
|
'Returns an ordering value for a particular attribute key.
Unrecognized attributes and OIDs will be sorted lexically at the end.
:return:
An orderable value.'
| @classmethod
def preferred_ordinal(cls, attr_name):
| attr_name = cls.map(attr_name)
if (attr_name in cls.preferred_order):
ordinal = cls.preferred_order.index(attr_name)
else:
ordinal = len(cls.preferred_order)
return (ordinal, attr_name)
|
':return:
A human-friendly unicode string to display to users'
| @property
def human_friendly(self):
| return {u'common_name': u'Common Name', u'surname': u'Surname', u'serial_number': u'Serial Number', u'country_name': u'Country', u'locality_name': u'Locality', u'state_or_province_name': u'State/Province', u'street_address': u'Street Address', u'organization_name': u'Organization', u'organizational_unit_name': u'Organizational Unit', u'title': u'Title', u'business_category': u'Business Category', u'postal_code': u'Postal Code', u'telephone_number': u'Telephone Number', u'name': u'Name', u'given_name': u'Given Name', u'initials': u'Initials', u'generation_qualifier': u'Generation Qualifier', u'unique_identifier': u'Unique Identifier', u'dn_qualifier': u'DN Qualifier', u'pseudonym': u'Pseudonym', u'email_address': u'Email Address', u'incorporation_locality': u'Incorporation Locality', u'incorporation_state_or_province': u'Incorporation State/Province', u'incorporation_country': u'Incorporation Country', u'domain_component': u'Domain Component', u'name_distinguisher': u'Name Distinguisher', u'organization_identifier': u'Organization Identifier'}.get(self.native, self.native)
|
'Returns the value after being processed by the internationalized string
preparation as specified by RFC 5280
:return:
A unicode string'
| @property
def prepped_value(self):
| if (self._prepped is None):
self._prepped = self._ldap_string_prep(self[u'value'].native)
return self._prepped
|
'Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.1
:param other:
Another NameTypeAndValue object
:return:
A boolean'
| def __eq__(self, other):
| if (not isinstance(other, NameTypeAndValue)):
return False
if (other[u'type'].native != self[u'type'].native):
return False
return (other.prepped_value == self.prepped_value)
|
'Implements the internationalized string preparation algorithm from
RFC 4518. https://tools.ietf.org/html/rfc4518#section-2
:param string:
A unicode string to prepare
:return:
A prepared unicode string, ready for comparison'
| def _ldap_string_prep(self, string):
| string = re.sub(u'[\xad\u1806\u034f\u180b-\u180d\ufe0f-\uff00\ufffc]+', u'', string)
string = re.sub(u'[ DCTB \n\x0b\x0c\r\x85]', u' ', string)
if (sys.maxunicode == 65535):
string = re.sub(u'\ud834[\udd73-\udd7a]|\udb40[\udc20-\udc7f]|\U000e0001', u'', string)
else:
string = re.sub(u'[\U0001d173-\U0001d17a\U000e0020-\U000e007f\U000e0001]', u'', string)
string = re.sub(u'[\x00-\x08\x0e-\x1f\x7f-\x84\x86-\x9f\u06dd\u070f\u180e\u200c-\u200f\u202a-\u202e\u2060-\u2063\u206a-\u206f\ufeff\ufff9-\ufffb]+', u'', string)
string = string.replace(u'\u200b', u'')
string = re.sub(u'[\xa0\u1680\u2000-\u200a\u2028-\u2029\u202f\u205f\u3000]', u' ', string)
string = u''.join(map(stringprep.map_table_b2, string))
string = unicodedata.normalize(u'NFKC', string)
for char in string:
if stringprep.in_table_a1(char):
raise ValueError(unwrap(u'\n X.509 Name objects may not contain unassigned code points\n '))
if stringprep.in_table_c8(char):
raise ValueError(unwrap(u'\n X.509 Name objects may not contain change display or\n zzzzdeprecated characters\n '))
if stringprep.in_table_c3(char):
raise ValueError(unwrap(u'\n X.509 Name objects may not contain private use characters\n '))
if stringprep.in_table_c4(char):
raise ValueError(unwrap(u'\n X.509 Name objects may not contain non-character code points\n '))
if stringprep.in_table_c5(char):
raise ValueError(unwrap(u'\n X.509 Name objects may not contain surrogate code points\n '))
if (char == u'\ufffd'):
raise ValueError(unwrap(u'\n X.509 Name objects may not contain the replacement character\n '))
has_r_and_al_cat = False
has_l_cat = False
for char in string:
if stringprep.in_table_d1(char):
has_r_and_al_cat = True
elif stringprep.in_table_d2(char):
has_l_cat = True
if has_r_and_al_cat:
first_is_r_and_al = stringprep.in_table_d1(string[0])
last_is_r_and_al = stringprep.in_table_d1(string[(-1)])
if (has_l_cat or (not first_is_r_and_al) or (not last_is_r_and_al)):
raise ValueError(unwrap(u'\n X.509 Name object contains a malformed bidirectional\n sequence\n '))
string = ((u' ' + re.sub(u' +', u' ', string).strip()) + u' ')
return string
|
':return:
A unicode string that can be used as a dict key or in a set'
| @property
def hashable(self):
| output = []
values = self._get_values(self)
for key in sorted(values.keys()):
output.append((u'%s: %s' % (key, values[key])))
return u'\x1f'.join(output)
|
'Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.1
:param other:
Another RelativeDistinguishedName object
:return:
A boolean'
| def __eq__(self, other):
| if (not isinstance(other, RelativeDistinguishedName)):
return False
if (len(self) != len(other)):
return False
self_types = self._get_types(self)
other_types = self._get_types(other)
if (self_types != other_types):
return False
self_values = self._get_values(self)
other_values = self._get_values(other)
for type_name_ in self_types:
if (self_values[type_name_] != other_values[type_name_]):
return False
return True
|
'Returns a set of types contained in an RDN
:param rdn:
A RelativeDistinguishedName object
:return:
A set object with unicode strings of NameTypeAndValue type field
values'
| def _get_types(self, rdn):
| return set([ntv[u'type'].native for ntv in rdn])
|
'Returns a dict of prepped values contained in an RDN
:param rdn:
A RelativeDistinguishedName object
:return:
A dict object with unicode strings of NameTypeAndValue value field
values that have been prepped for comparison'
| def _get_values(self, rdn):
| output = {}
[output.update([(ntv[u'type'].native, ntv.prepped_value)]) for ntv in rdn]
return output
|
':return:
A unicode string that can be used as a dict key or in a set'
| @property
def hashable(self):
| return u'\x1e'.join((rdn.hashable for rdn in self))
|
'Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.1
:param other:
Another RDNSequence object
:return:
A boolean'
| def __eq__(self, other):
| if (not isinstance(other, RDNSequence)):
return False
if (len(self) != len(other)):
return False
for (index, self_rdn) in enumerate(self):
if (other[index] != self_rdn):
return False
return True
|
'Creates a Name object from a dict of unicode string keys and values.
The keys should be from NameType._map, or a dotted-integer OID unicode
string.
:param name_dict:
A dict of name information, e.g. {"common_name": "Will Bond",
"country_name": "US", "organization": "Codex Non Sufficit LC"}
:param use_printable:
A bool - if PrintableString should be used for encoding instead of
UTF8String. This is for backwards compatiblity with old software.
:return:
An x509.Name object'
| @classmethod
def build(cls, name_dict, use_printable=False):
| rdns = []
if (not use_printable):
encoding_name = u'utf8_string'
encoding_class = UTF8String
else:
encoding_name = u'printable_string'
encoding_class = PrintableString
name_dict = OrderedDict(sorted(name_dict.items(), key=(lambda item: NameType.preferred_ordinal(item[0]))))
for (attribute_name, attribute_value) in name_dict.items():
attribute_name = NameType.map(attribute_name)
if (attribute_name == u'email_address'):
value = EmailAddress(attribute_value)
elif (attribute_name == u'domain_component'):
value = DNSName(attribute_value)
elif (attribute_name in set([u'dn_qualifier', u'country_name', u'serial_number'])):
value = DirectoryString(name=u'printable_string', value=PrintableString(attribute_value))
else:
value = DirectoryString(name=encoding_name, value=encoding_class(attribute_value))
rdns.append(RelativeDistinguishedName([NameTypeAndValue({u'type': attribute_name, u'value': value})]))
return cls(name=u'', value=RDNSequence(rdns))
|
':return:
A unicode string that can be used as a dict key or in a set'
| @property
def hashable(self):
| return self.chosen.hashable
|
'Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.1
:param other:
Another Name object
:return:
A boolean'
| def __eq__(self, other):
| if (not isinstance(other, Name)):
return False
return (self.chosen == other.chosen)
|
':return:
A human-friendly unicode string containing the parts of the name'
| @property
def human_friendly(self):
| if (self._human_friendly is None):
data = OrderedDict()
last_field = None
for rdn in self.chosen:
for type_val in rdn:
field_name = type_val[u'type'].human_friendly
last_field = field_name
if (field_name in data):
data[field_name] = [data[field_name]]
data[field_name].append(type_val[u'value'])
else:
data[field_name] = type_val[u'value']
to_join = []
keys = data.keys()
if (last_field == u'Country'):
keys = reversed(list(keys))
for key in keys:
value = data[key]
native_value = self._recursive_humanize(value)
to_join.append((u'%s: %s' % (key, native_value)))
has_comma = False
for element in to_join:
if (element.find(u',') != (-1)):
has_comma = True
break
separator = (u', ' if (not has_comma) else u'; ')
self._human_friendly = separator.join(to_join[::(-1)])
return self._human_friendly
|
'Recursively serializes data compiled from the RDNSequence
:param value:
An Asn1Value object, or a list of Asn1Value objects
:return:
A unicode string'
| def _recursive_humanize(self, value):
| if isinstance(value, list):
return u', '.join(reversed([self._recursive_humanize(sub_value) for sub_value in value]))
return value.native
|
':return:
The SHA1 hash of the DER-encoded bytes of this name'
| @property
def sha1(self):
| if (self._sha1 is None):
self._sha1 = hashlib.sha1(self.dump()).digest()
return self._sha1
|
':return:
The SHA-256 hash of the DER-encoded bytes of this name'
| @property
def sha256(self):
| if (self._sha256 is None):
self._sha256 = hashlib.sha256(self.dump()).digest()
return self._sha256
|
'Does not support other_name, x400_address or edi_party_name
:param other:
The other GeneralName to compare to
:return:
A boolean'
| def __eq__(self, other):
| if (self.name in (u'other_name', u'x400_address', u'edi_party_name')):
raise ValueError(unwrap(u'\n Comparison is not supported for GeneralName objects of\n choice %s\n ', self.name))
if (other.name in (u'other_name', u'x400_address', u'edi_party_name')):
raise ValueError(unwrap(u'\n Comparison is not supported for GeneralName objects of choice\n %s', other.name))
if (self.name != other.name):
return False
return (self.chosen == other.chosen)
|
':return:
None or a unicode string of the distribution point\'s URL'
| @property
def url(self):
| if (self._url is False):
self._url = None
name = self[u'distribution_point']
if (name.name != u'full_name'):
raise ValueError(unwrap(u'\n CRL distribution points that are relative to the issuer are\n not supported\n '))
for general_name in name.chosen:
if (general_name.name == u'uniform_resource_identifier'):
url = general_name.native
if (url[0:7] == u'http://'):
self._url = url
break
return self._url
|
'Sets common named extensions to private attributes and creates a list
of critical extensions'
| def _set_extensions(self):
| self._critical_extensions = set()
for extension in self[u'tbs_certificate'][u'extensions']:
name = extension[u'extn_id'].native
attribute_name = (u'_%s_value' % name)
if hasattr(self, attribute_name):
setattr(self, attribute_name, extension[u'extn_value'].parsed)
if extension[u'critical'].native:
self._critical_extensions.add(name)
self._processed_extensions = True
|
'Returns a set of the names (or OID if not a known extension) of the
extensions marked as critical
:return:
A set of unicode strings'
| @property
def critical_extensions(self):
| if (not self._processed_extensions):
self._set_extensions()
return self._critical_extensions
|
'This extension is used to contain additional identification attributes
about the subject.
:return:
None or an Attributes object'
| @property
def subject_directory_attributes_value(self):
| if (not self._processed_extensions):
self._set_extensions()
return self._key_identifier_value
|
'This extension is used to help in creating certificate validation paths.
It contains an identifier that should generally, but is not guaranteed
to, be unique.
:return:
None or an OctetString object'
| @property
def key_identifier_value(self):
| if (not self._processed_extensions):
self._set_extensions()
return self._key_identifier_value
|
'This extension is used to define the purpose of the public key
contained within the certificate.
:return:
None or a KeyUsage'
| @property
def key_usage_value(self):
| if (not self._processed_extensions):
self._set_extensions()
return self._key_usage_value
|
'This extension allows for additional names to be associate with the
subject of the certificate. While it may contain a whole host of
possible names, it is usually used to allow certificates to be used
with multiple different domain names.
:return:
None or a GeneralNames object'
| @property
def subject_alt_name_value(self):
| if (not self._processed_extensions):
self._set_extensions()
return self._subject_alt_name_value
|
'This extension allows associating one or more alternative names with
the issuer of the certificate.
:return:
None or an x509.GeneralNames object'
| @property
def issuer_alt_name_value(self):
| if (not self._processed_extensions):
self._set_extensions()
return self._issuer_alt_name_value
|
'This extension is used to determine if the subject of the certificate
is a CA, and if so, what the maximum number of intermediate CA certs
after this are, before an end-entity certificate is found.
:return:
None or a BasicConstraints object'
| @property
def basic_constraints_value(self):
| if (not self._processed_extensions):
self._set_extensions()
return self._basic_constraints_value
|
'This extension is used in CA certificates, and is used to limit the
possible names of certificates issued.
:return:
None or a NameConstraints object'
| @property
def name_constraints_value(self):
| if (not self._processed_extensions):
self._set_extensions()
return self._name_constraints_value
|
'This extension is used to help in locating the CRL for this certificate.
:return:
None or a CRLDistributionPoints object
extension'
| @property
def crl_distribution_points_value(self):
| if (not self._processed_extensions):
self._set_extensions()
return self._crl_distribution_points_value
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.