code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
gitignore_path = os.path.join(root, '.gitignore')
dir_patterns = ['.git']
file_patterns = []
if not os.path.exists(gitignore_path):
return (dir_patterns, file_patterns)
with open(gitignore_path, 'r', encoding='utf-8') as f:
for line in f.readlines():
line = line.... | def _gitignore(root) | Parses a .gitignore file and returns patterns to match dirs and files.
Only basic gitignore patterns are supported. Pattern negation, ** wildcards
and anchored patterns are not currently implemented.
:param root:
A unicode string of the path to the git repository
:return:
A 2-element t... | 2.118818 | 1.868179 | 1.134162 |
proc = subprocess.Popen(
params,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=cwd
)
stdout, stderr = proc.communicate()
code = proc.wait()
if code != 0:
e = OSError('subprocess exit code for %r was %d: %s' % (params, code, stderr))
e.stdou... | def _execute(params, cwd) | Executes a subprocess
:param params:
A list of the executable and arguments to pass to it
:param cwd:
The working directory to execute the command in
:return:
A 2-element tuple of (stdout, stderr) | 2.503202 | 2.339519 | 1.069965 |
deps_dir = os.path.join(build_root, 'modularcrypto-deps')
if os.path.exists(deps_dir):
shutil.rmtree(deps_dir, ignore_errors=True)
os.mkdir(deps_dir)
try:
print("Staging ci dependencies")
_stage_requirements(deps_dir, os.path.join(package_root, 'requires', 'ci'))
... | def run() | Installs required development dependencies. Uses git to checkout other
modularcrypto repos for more accurate coverage data. | 3.277247 | 2.935947 | 1.116249 |
print('Downloading %s' % url)
filename = os.path.basename(url)
dest_path = os.path.join(dest, filename)
if sys.platform == 'win32':
powershell_exe = os.path.join('system32\\WindowsPowerShell\\v1.0\\powershell.exe')
code = "[System.Net.ServicePointManager]::SecurityProtocol = [Syst... | def _download(url, dest) | Downloads a URL to a directory
:param url:
The URL to download
:param dest:
The path to the directory to save the file in
:return:
The filesystem path to the saved file | 2.417534 | 2.491804 | 0.970194 |
if path.endswith('.zip'):
return zipfile.ZipFile(path, 'r')
return tarfile.open(path, 'r') | def _open_archive(path) | :param path:
A unicode string of the filesystem path to the archive
:return:
An archive object | 2.948803 | 3.062303 | 0.962936 |
if isinstance(archive, zipfile.ZipFile):
return archive.infolist()
return archive.getmembers() | def _list_archive_members(archive) | :param archive:
An archive from _open_archive()
:return:
A list of info objects to be used with _info_name() and _extract_info() | 5.444828 | 4.690474 | 1.160827 |
common_root = None
for info in _list_archive_members(archive):
fn = _info_name(info)
if fn in set(['.', '/']):
continue
sep = None
if '/' in fn:
sep = '/'
elif '\\' in fn:
sep = '\\'
if sep is None:
root_dir = ... | def _archive_single_dir(archive) | Check if all members of the archive are in a single top-level directory
:param archive:
An archive from _open_archive()
:return:
None if not a single top level directory in archive, otherwise a
unicode string of the top level directory name | 3.121292 | 2.740305 | 1.139031 |
if isinstance(info, zipfile.ZipInfo):
return info.filename.replace('\\', '/')
return info.name.replace('\\', '/') | def _info_name(info) | Returns a normalized file path for an archive info object
:param info:
An info object from _list_archive_members()
:return:
A unicode string with all directory separators normalized to "/" | 4.354778 | 3.629455 | 1.199844 |
if isinstance(archive, zipfile.ZipFile):
fn = info.filename
is_dir = fn.endswith('/') or fn.endswith('\\')
out = archive.read(info)
if is_dir and out == b'':
return None
return out
info_file = archive.extractfile(info)
if info_file:
return i... | def _extract_info(archive, info) | Extracts the contents of an archive info object
;param archive:
An archive from _open_archive()
:param info:
An info object from _list_archive_members()
:return:
None, or a byte string of the file contents | 3.134584 | 3.11325 | 1.006853 |
if pkg_path.endswith('.exe'):
try:
zf = None
zf = zipfile.ZipFile(pkg_path, 'r')
# Exes have a PLATLIB folder containing everything we want
for zi in zf.infolist():
if not zi.filename.startswith('PLATLIB'):
continue
... | def _extract_package(deps_dir, pkg_path) | Extract a .whl, .zip, .tar.gz or .tar.bz2 into a package path to
use when running CI tasks
:param deps_dir:
A unicode string of the directory the package should be extracted to
:param pkg_path:
A unicode string of the path to the archive | 2.568655 | 2.586225 | 0.993206 |
valid_tags = _pep425tags()
exe_suffix = None
if sys.platform == 'win32' and _pep425_implementation() == 'cp':
win_arch = 'win32' if sys.maxsize == 2147483647 else 'win-amd64'
version_info = sys.version_info
exe_suffix = '.%s-py%d.%d.exe' % (win_arch, version_info[0], version_i... | def _stage_requirements(deps_dir, path) | Installs requirements without using Python to download, since
different services are limiting to TLS 1.2, and older version of
Python do not support that
:param deps_dir:
A unicode path to a temporary diretory to use for downloads
:param path:
A unicoe filesystem path to a requirements... | 2.327626 | 2.356812 | 0.987616 |
python_version = '.'.join(map(str_cls, sys.version_info[0:2]))
sys_platform = sys.platform
packages = []
with open(path, 'rb') as f:
contents = f.read().decode('utf-8')
for line in re.split(r'\r?\n', contents):
line = line.strip()
if not len(line):
contin... | def _parse_requires(path) | Does basic parsing of pip requirements files, to allow for
using something other than Python to do actual TLS requests
:param path:
A path to a requirements file
:return:
A list of dict objects containing the keys:
- 'type' ('any', 'url', '==', '>=')
- 'pkg'
- 'v... | 2.089046 | 1.921469 | 1.087213 |
if not isinstance(byte_string, byte_cls):
raise TypeError(unwrap(
'''
byte_string must be a byte string, not %s
''',
_type_name(byte_string)
))
return byte_string.find(b'-----BEGIN') != -1 or byte_string.find(b'---- BEGIN') != -1 | def detect(byte_string) | Detect if a byte string seems to contain a PEM-encoded block
:param byte_string:
A byte string to look through
:return:
A boolean, indicating if a PEM-encoded block is contained in the byte
string | 3.675075 | 3.130826 | 1.173836 |
if not isinstance(der_bytes, byte_cls):
raise TypeError(unwrap(
'''
der_bytes must be a byte string, not %s
''' % _type_name(der_bytes)
))
if not isinstance(type_name, str_cls):
raise TypeError(unwrap(
'''
type_name must ... | def armor(type_name, der_bytes, headers=None) | Armors a DER-encoded byte string in PEM
:param type_name:
A unicode string that will be capitalized and placed in the header
and footer of the block. E.g. "CERTIFICATE", "PRIVATE KEY", etc. This
will appear as "-----BEGIN CERTIFICATE-----" and
"-----END CERTIFICATE-----".
:para... | 1.713279 | 1.614682 | 1.061063 |
if not isinstance(pem_bytes, byte_cls):
raise TypeError(unwrap(
'''
pem_bytes must be a byte string, not %s
''',
_type_name(pem_bytes)
))
# Valid states include: "trash", "headers", "body"
state = 'trash'
headers = {}
base64_data... | def _unarmor(pem_bytes) | Convert a PEM-encoded byte string into one or more DER-encoded byte strings
:param pem_bytes:
A byte string of the PEM-encoded data
:raises:
ValueError - when the pem_bytes do not appear to be PEM-encoded bytes
:return:
A generator of 3-element tuples in the format: (object_type, ... | 3.395435 | 3.172786 | 1.070175 |
generator = _unarmor(pem_bytes)
if not multiple:
return next(generator)
return generator | def unarmor(pem_bytes, multiple=False) | Convert a PEM-encoded byte string into a DER-encoded byte string
:param pem_bytes:
A byte string of the PEM-encoded data
:param multiple:
If True, function will return a generator
:raises:
ValueError - when the pem_bytes do not appear to be PEM-encoded bytes
:return:
... | 6.111073 | 9.62762 | 0.634744 |
algorithm = self['algorithm'].native
algo_map = {
'md2_rsa': 'rsassa_pkcs1v15',
'md5_rsa': 'rsassa_pkcs1v15',
'sha1_rsa': 'rsassa_pkcs1v15',
'sha224_rsa': 'rsassa_pkcs1v15',
'sha256_rsa': 'rsassa_pkcs1v15',
'sha384_rsa': ... | def signature_algo(self) | :return:
A unicode string of "rsassa_pkcs1v15", "rsassa_pss", "dsa" or
"ecdsa" | 1.470094 | 1.398143 | 1.051461 |
algorithm = self['algorithm'].native
algo_map = {
'md2_rsa': 'md2',
'md5_rsa': 'md5',
'sha1_rsa': 'sha1',
'sha224_rsa': 'sha224',
'sha256_rsa': 'sha256',
'sha384_rsa': 'sha384',
'sha512_rsa': 'sha512',
... | def hash_algo(self) | :return:
A unicode string of "md2", "md5", "sha1", "sha224", "sha256",
"sha384", "sha512", "sha512_224", "sha512_256" | 1.717846 | 1.681179 | 1.02181 |
r = int_from_bytes(data[0:len(data) // 2])
s = int_from_bytes(data[len(data) // 2:])
return cls({'r': r, 's': s}) | def from_p1363(cls, data) | 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 | 3.092902 | 3.754016 | 0.823892 |
r_bytes = int_to_bytes(self['r'].native)
s_bytes = int_to_bytes(self['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 | def to_p1363(self) | Dumps a signature to a byte string compatible with Microsoft's
BCryptVerifySignature() function.
:return:
A byte string compatible with BCryptVerifySignature() | 2.937663 | 2.708892 | 1.084452 |
encryption_algo = self['algorithm'].native
if encryption_algo == 'pbes2':
return self['parameters']['key_derivation_func']['algorithm'].native
if encryption_algo.find('.') == -1:
if encryption_algo.find('_') != -1:
encryption_algo, _ = encrypti... | def kdf(self) | Returns the name of the key derivation function to use.
:return:
A unicode from of one of the following: "pbkdf1", "pbkdf2",
"pkcs12_kdf" | 3.454074 | 3.147467 | 1.097414 |
encryption_algo = self['algorithm'].native
if encryption_algo == 'pbes2':
return self['parameters']['key_derivation_func']['parameters']['prf']['algorithm'].native
if encryption_algo.find('.') == -1:
if encryption_algo.find('_') != -1:
_, hmac_... | def kdf_hmac(self) | 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" | 4.330334 | 4.332517 | 0.999496 |
encryption_algo = self['algorithm'].native
if encryption_algo == 'pbes2':
salt = self['parameters']['key_derivation_func']['parameters']['salt']
if salt.name == 'other_source':
raise ValueError(unwrap(
'''
Can no... | def kdf_salt(self) | Returns the byte string to use as the salt for the KDF.
:return:
A byte string | 5.256238 | 5.339802 | 0.984351 |
encryption_algo = self['algorithm'].native
if encryption_algo == 'pbes2':
return self['parameters']['key_derivation_func']['parameters']['iteration_count'].native
if encryption_algo.find('.') == -1:
if encryption_algo.find('_') != -1:
return se... | def kdf_iterations(self) | Returns the number of iterations that should be run via the KDF.
:return:
An integer | 4.459108 | 4.823882 | 0.924382 |
encryption_algo = self['algorithm'].native
if encryption_algo[0:3] == 'aes':
return {
'aes128_': 16,
'aes192_': 24,
'aes256_': 32,
}[encryption_algo[0:7]]
cipher_lengths = {
'des': 8,
'tri... | def key_length(self) | 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.
... | 3.211862 | 3.064108 | 1.048221 |
encryption_algo = self['algorithm'].native
if encryption_algo[0:7] in set(['aes128_', 'aes192_', 'aes256_']):
return encryption_algo[7:]
if encryption_algo[0:6] == 'pbes1_':
return 'cbc'
if encryption_algo[0:7] == 'pkcs12_':
return 'cbc'
... | def encryption_mode(self) | 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" | 3.7495 | 3.599546 | 1.041659 |
encryption_algo = self['algorithm'].native
if encryption_algo[0:7] in set(['aes128_', 'aes192_', 'aes256_']):
return 'aes'
if encryption_algo in set(['des', 'rc2', 'rc5']):
return encryption_algo
if encryption_algo == 'tripledes_3key':
ret... | def encryption_cipher(self) | 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",
... | 2.258897 | 2.247345 | 1.00514 |
encryption_algo = self['algorithm'].native
if encryption_algo[0:7] in set(['aes128_', 'aes192_', 'aes256_']):
return 16
cipher_map = {
'des': 8,
'tripledes_3key': 8,
'rc2': 8,
}
if encryption_algo in cipher_map:
... | def encryption_block_size(self) | Returns the block size of the encryption cipher, in bytes.
:return:
An integer that is the block size in bytes | 2.407027 | 2.477194 | 0.971675 |
encryption_algo = self['algorithm'].native
if encryption_algo in set(['rc2', 'rc5']):
return self['parameters'].parsed['iv'].native
# For DES/Triple DES and AES the IV is the entirety of the parameters
octet_string_iv_oids = set([
'des',
't... | def encryption_iv(self) | 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 | 5.189391 | 4.756805 | 1.09094 |
if not isinstance(value, str_cls):
raise TypeError(unwrap(
'''
%s value must be a unicode string, not %s
''',
type_name(self),
type_name(value)
))
if value.startswith('.'):
enco... | def set(self, value) | Sets the value of the DNS name
:param value:
A unicode string | 3.567748 | 3.450544 | 1.033967 |
if not isinstance(value, str_cls):
raise TypeError(unwrap(
'''
%s value must be a unicode string, not %s
''',
type_name(self),
type_name(value)
))
self._unicode = value
self.content... | def set(self, value) | Sets the value of the string
:param value:
A unicode string | 4.933894 | 4.72557 | 1.044085 |
if not isinstance(value, str_cls):
raise TypeError(unwrap(
'''
%s value must be a unicode string, not %s
''',
type_name(self),
type_name(value)
))
if value.find('@') != -1:
mail... | def set(self, value) | Sets the value of the string
:param value:
A unicode string | 3.538913 | 3.494929 | 1.012585 |
if not isinstance(value, str_cls):
raise TypeError(unwrap(
'''
%s value must be a unicode string, not %s
''',
type_name(self),
type_name(value)
))
original_value = value
has_cidr =... | def set(self, value) | 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 | 2.232602 | 2.16518 | 1.031139 |
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:... | def native(self) | The native Python datatype representation of this value
:return:
A unicode string or None | 2.747033 | 2.595093 | 1.058549 |
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) | def preferred_ordinal(cls, attr_name) | Returns an ordering value for a particular attribute key.
Unrecognized attributes and OIDs will be sorted lexically at the end.
:return:
An orderable value. | 3.046507 | 2.875407 | 1.059505 |
if self._prepped is None:
self._prepped = self._ldap_string_prep(self['value'].native)
return self._prepped | def prepped_value(self) | Returns the value after being processed by the internationalized string
preparation as specified by RFC 5280
:return:
A unicode string | 9.003098 | 6.479469 | 1.389481 |
output = []
values = self._get_values(self)
for key in sorted(values.keys()):
output.append('%s: %s' % (key, values[key]))
# Unit separator is used here since the normalization process for
# values moves any such character, and the keys are all dotted intege... | def hashable(self) | :return:
A unicode string that can be used as a dict key or in a set | 15.441441 | 14.569115 | 1.059875 |
output = {}
[output.update([(ntv['type'].native, ntv.prepped_value)]) for ntv in rdn]
return output | def _get_values(self, 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 | 15.777215 | 10.538069 | 1.497164 |
rdns = []
if not use_printable:
encoding_name = 'utf8_string'
encoding_class = UTF8String
else:
encoding_name = 'printable_string'
encoding_class = PrintableString
# Sort the attributes according to NameType.preferred_order
... | def build(cls, name_dict, use_printable=False) | 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": "Code... | 3.020569 | 2.816678 | 1.072387 |
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['type'].human_friendly
last_field = field_name
if f... | def human_friendly(self) | :return:
A human-friendly unicode string containing the parts of the name | 3.038481 | 2.910851 | 1.043846 |
if isinstance(value, list):
return', '.join(
reversed([self._recursive_humanize(sub_value) for sub_value in value])
)
return value.native | def _recursive_humanize(self, value) | Recursively serializes data compiled from the RDNSequence
:param value:
An Asn1Value object, or a list of Asn1Value objects
:return:
A unicode string | 5.845351 | 5.102827 | 1.145512 |
if self._sha1 is None:
self._sha1 = hashlib.sha1(self.dump()).digest()
return self._sha1 | def sha1(self) | :return:
The SHA1 hash of the DER-encoded bytes of this name | 3.808002 | 3.457388 | 1.10141 |
if self._sha256 is None:
self._sha256 = hashlib.sha256(self.dump()).digest()
return self._sha256 | def sha256(self) | :return:
The SHA-256 hash of the DER-encoded bytes of this name | 2.873336 | 2.658635 | 1.080756 |
if self._url is False:
self._url = None
name = self['distribution_point']
if name.name != 'full_name':
raise ValueError(unwrap(
'''
CRL distribution points that are relative to the issuer are
... | def url(self) | :return:
None or a unicode string of the distribution point's URL | 5.217427 | 4.345011 | 1.200786 |
if self._issuer_serial is None:
self._issuer_serial = self.issuer.sha256 + b':' + str_cls(self.serial_number).encode('ascii')
return self._issuer_serial | def issuer_serial(self) | :return:
A byte string of the SHA-256 hash of the issuer concatenated with
the ascii character ":", concatenated with the serial number as
an ascii string | 4.710316 | 3.213728 | 1.465686 |
if self._authority_issuer_serial is False:
akiv = self.authority_key_identifier_value
if akiv and akiv['authority_cert_issuer'].native:
issuer = self.authority_key_identifier_value['authority_cert_issuer'][0].chosen
# We untag the element since i... | def authority_issuer_serial(self) | :return:
None or a byte string of the SHA-256 hash of the isser from the
authority key identifier extension concatenated with the ascii
character ":", concatenated with the serial number from the
authority key identifier extension as an ascii string | 4.987234 | 4.344884 | 1.147841 |
if self._crl_distribution_points is None:
self._crl_distribution_points = self._get_http_crl_distribution_points(self.crl_distribution_points_value)
return self._crl_distribution_points | def crl_distribution_points(self) | Returns complete CRL URLs - does not include delta CRLs
:return:
A list of zero or more DistributionPoint objects | 2.883528 | 2.829185 | 1.019208 |
if self._delta_crl_distribution_points is None:
self._delta_crl_distribution_points = self._get_http_crl_distribution_points(self.freshest_crl_value)
return self._delta_crl_distribution_points | def delta_crl_distribution_points(self) | Returns delta CRL URLs - does not include complete CRLs
:return:
A list of zero or more DistributionPoint objects | 2.888135 | 2.786861 | 1.03634 |
output = []
if crl_distribution_points is None:
return []
for distribution_point in crl_distribution_points:
distribution_point_name = distribution_point['distribution_point']
if distribution_point_name is VOID:
continue
... | def _get_http_crl_distribution_points(self, crl_distribution_points) | Fetches the DistributionPoint object for non-relative, HTTP CRLs
referenced by the certificate
:param crl_distribution_points:
A CRLDistributionPoints object to grab the DistributionPoints from
:return:
A list of zero or more DistributionPoint objects | 4.610622 | 4.25421 | 1.083779 |
if not self.authority_information_access_value:
return []
output = []
for entry in self.authority_information_access_value:
if entry['access_method'].native == 'ocsp':
location = entry['access_location']
if location.name != 'unif... | def ocsp_urls(self) | :return:
A list of zero or more unicode strings of the OCSP URLs for this
cert | 3.180342 | 2.976171 | 1.068602 |
if self._valid_domains is None:
self._valid_domains = []
# For the subject alt name extension, we can look at the name of
# the choice selected since it distinguishes between domain names,
# email addresses, IPs, etc
if self.subject_alt_name... | def valid_domains(self) | :return:
A list of unicode strings of valid domain names for the certificate.
Wildcard certificates will have a domain in the form: *.example.com | 3.277309 | 3.131069 | 1.046706 |
if self._valid_ips is None:
self._valid_ips = []
if self.subject_alt_name_value:
for general_name in self.subject_alt_name_value:
if general_name.name == 'ip_address':
self._valid_ips.append(general_name.native)
... | def valid_ips(self) | :return:
A list of unicode strings of valid IP addresses for the certificate | 3.462359 | 2.864549 | 1.208693 |
if self._self_issued is None:
self._self_issued = self.subject == self.issuer
return self._self_issued | def self_issued(self) | :return:
A boolean - if the certificate is self-issued, as defined by RFC
5280 | 3.959111 | 3.44253 | 1.150059 |
if self._self_signed is None:
self._self_signed = 'no'
if self.self_issued:
if self.key_identifier:
if not self.authority_key_identifier:
self._self_signed = 'maybe'
elif self.authority_key_identifi... | def self_signed(self) | :return:
A unicode string of "no" or "maybe". The "maybe" result will
be returned if the certificate issuer and subject are the same.
If a key identifier and authority key identifier are present,
they will need to match otherwise "no" will be returned.
To ver... | 2.514514 | 2.019862 | 1.244894 |
if not isinstance(domain_ip, str_cls):
raise TypeError(unwrap(
'''
domain_ip must be a unicode string, not %s
''',
type_name(domain_ip)
))
encoded_domain_ip = domain_ip.encode('idna').decode('ascii').lower... | def is_valid_domain_ip(self, domain_ip) | Check if a domain name or IP address is valid according to the
certificate
:param domain_ip:
A unicode string of a domain name or IP address
:return:
A boolean - if the domain or IP is valid for the certificate | 2.07419 | 2.02434 | 1.024625 |
# The * character must be present for a wildcard match, and if there is
# most than one, it is an invalid wildcard specification
if domain.count('*') != 1:
return False
labels = domain.lower().split('.')
if not labels:
return False
# W... | def _is_wildcard_domain(self, domain) | Checks if a domain is a valid wildcard according to
https://tools.ietf.org/html/rfc6125#section-6.4.3
:param domain:
A unicode string of the domain name, where any U-labels from an IDN
have been converted to A-labels
:return:
A boolean - if the domain is a v... | 6.222802 | 5.533486 | 1.124572 |
first_domain_label = domain_labels[0]
other_domain_labels = domain_labels[1:]
wildcard_label = valid_domain_labels[0]
other_valid_domain_labels = valid_domain_labels[1:]
# The wildcard is only allowed in the first label, so if
# The subsequent labels are not e... | def _is_wildcard_match(self, domain_labels, valid_domain_labels) | Determines if the labels in a domain are a match for labels from a
wildcard valid domain name
:param domain_labels:
A list of unicode strings, with A-label form for IDNs, of the labels
in the domain name to check
:param valid_domain_labels:
A list of unicode... | 2.610192 | 2.654389 | 0.98335 |
y2 = point.y * point.y
x3 = point.x * point.x * point.x
return (y2 - (x3 + self.a * point.x + self.b)) % self.p == 0 | def contains(self, point) | :param point:
A Point object
:return:
Boolean if the point is on this curve | 3.968583 | 3.61294 | 1.098436 |
# X9.62 B.3:
p = self.curve.p
a = self.curve.a
l_ = ((3 * self.x * self.x + a) * inverse_mod(2 * self.y, p)) % p
x3 = (l_ * l_ - 2 * self.x) % p
y3 = (l_ * (self.x - x3) - self.y) % p
return PrimePoint(self.curve, x3, y3) | def double(self) | :return:
A PrimePoint object that is twice this point | 3.051482 | 2.540872 | 1.200959 |
print('Running flake8 %s' % flake8.__version__)
flake8_style = get_style_guide(config_file=os.path.join(package_root, 'tox.ini'))
paths = []
for _dir in [package_name, 'dev', 'tests']:
for root, _, filenames in os.walk(_dir):
for filename in filenames:
if not ... | def run() | Runs flake8 lint
:return:
A bool - if flake8 did not find any errors | 3.061308 | 2.835523 | 1.079627 |
print('Python ' + sys.version.replace('\n', ''))
try:
oscrypto_tests_module_info = imp.find_module('tests', [os.path.join(build_root, 'oscrypto')])
oscrypto_tests = imp.load_module('oscrypto.tests', *oscrypto_tests_module_info)
oscrypto = oscrypto_tests.local_oscrypto()
pr... | def run() | Runs the linter and tests
:return:
A bool - if the linter and tests ran successfully | 3.774082 | 3.636233 | 1.03791 |
if address_family not in set([socket.AF_INET, socket.AF_INET6]):
raise ValueError(unwrap(
'''
address_family must be socket.AF_INET (%s) or socket.AF_INET6 (%s),
not %s
''',
repr(socket.AF_INET),
repr(socket.AF_INET6),
... | def inet_ntop(address_family, packed_ip) | Windows compatibility shim for socket.inet_ntop().
:param address_family:
socket.AF_INET for IPv4 or socket.AF_INET6 for IPv6
:param packed_ip:
A byte string of the network form of an IP address
:return:
A unicode string of the IP address | 2.042247 | 2.025353 | 1.008341 |
if address_family not in set([socket.AF_INET, socket.AF_INET6]):
raise ValueError(unwrap(
'''
address_family must be socket.AF_INET (%s) or socket.AF_INET6 (%s),
not %s
''',
repr(socket.AF_INET),
repr(socket.AF_INET6),
... | def inet_pton(address_family, ip_string) | Windows compatibility shim for socket.inet_ntop().
:param address_family:
socket.AF_INET for IPv4 or socket.AF_INET6 for IPv6
:param ip_string:
A unicode string of an IP address
:return:
A byte string of the network form of the IP address | 1.767658 | 1.7636 | 1.002301 |
format = format.replace('%Y', '0000')
# Year 0 is 1BC and a leap year. Leap years repeat themselves
# every 28 years. Because of adjustments and the proleptic gregorian
# calendar, the simplest way to format is to substitute year 2000.
temp = date(2000, self.month, self... | def _format(self, format) | Performs strftime(), always returning a unicode string
:param format:
A strftime() format string
:return:
A unicode string of the formatted date | 3.52257 | 3.399749 | 1.036126 |
output = self._format(format)
if py2:
return output.encode('utf-8')
return output | def strftime(self, format) | 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 | 6.466551 | 6.568917 | 0.984417 |
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,... | def replace(self, year=None, month=None, day=None) | 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 | 2.668661 | 2.251365 | 1.185353 |
if self.tzinfo is None:
return None
return self.tzinfo.utcoffset(self.replace(year=2000)) | def utcoffset(self) | :return:
None or a datetime.timedelta() of the offset from UTC | 3.936131 | 3.256015 | 1.20888 |
if self.tzinfo is None:
return None
return self.tzinfo.dst(self.replace(year=2000)) | def dst(self) | :return:
None or a datetime.timedelta() of the daylight savings time offset | 6.19387 | 3.674588 | 1.685595 |
if self.tzinfo is None:
return None
return self.tzinfo.tzname(self.replace(year=2000)) | def tzname(self) | :return:
None or the name of the timezone as a unicode string in Python 3
and a byte string in Python 2 | 3.899357 | 3.32442 | 1.172943 |
format = format.replace('%Y', '0000')
# Year 0 is 1BC and a leap year. Leap years repeat themselves
# every 28 years. Because of adjustments and the proleptic gregorian
# calendar, the simplest way to format is to substitute year 2000.
temp = datetime(
2000,... | def _format(self, format) | Performs strftime(), always returning a unicode string
:param format:
A strftime() format string
:return:
A unicode string of the formatted datetime | 3.195749 | 3.094748 | 1.032636 |
if self.microsecond == 0:
return self.strftime('0000-%%m-%%d%s%%H:%%M:%%S' % sep)
return self.strftime('0000-%%m-%%d%s%%H:%%M:%%S.%%f' % sep) | def isoformat(self, sep='T') | 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
... | 3.052492 | 2.901801 | 1.05193 |
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:
... | def replace(self, year=None, month=None, day=None, hour=None, minute=None,
second=None, microsecond=None, tzinfo=None) | 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 | 1.551092 | 1.482409 | 1.046332 |
if self._issuer_name is False:
self._issuer_name = None
if self.certificate_issuer_value:
for general_name in self.certificate_issuer_value:
if general_name.name == 'directory_name':
self._issuer_name = general_name.ch... | def issuer_name(self) | :return:
None, or an asn1crypto.x509.Name object for the issuer of the cert | 3.715186 | 3.104805 | 1.196592 |
if self._issuer_cert_urls is None:
self._issuer_cert_urls = []
if self.authority_information_access_value:
for entry in self.authority_information_access_value:
if entry['access_method'].native == 'ca_issuers':
locatio... | def issuer_cert_urls(self) | :return:
A list of unicode strings that are URLs that should contain either
an individual DER-encoded X.509 certificate, or a DER-encoded CMS
message containing multiple certificates | 2.687798 | 2.570978 | 1.045438 |
if self._delta_crl_distribution_points is None:
self._delta_crl_distribution_points = []
if self.freshest_crl_value is not None:
for distribution_point in self.freshest_crl_value:
distribution_point_name = distribution_point['distribution_po... | def delta_crl_distribution_points(self) | Returns delta CRL URLs - only applies to complete CRLs
:return:
A list of zero or more DistributionPoint objects | 3.443708 | 3.281429 | 1.049454 |
self._critical_extensions = set()
for extension in self['single_extensions']:
name = extension['extn_id'].native
attribute_name = '_%s_value' % name
if hasattr(self, attribute_name):
setattr(self, attribute_name, extension['extn_value'].pars... | def _set_extensions(self) | Sets common named extensions to private attributes and creates a list
of critical extensions | 4.355501 | 3.609821 | 1.20657 |
print('%s%s Object #%s' % (prefix, type_name(self), id(self)))
if self._header:
print('%s Header: 0x%s' % (prefix, binascii.hexlify(self._header or b'').decode('utf-8')))
has_header = self.method is not None and self.class_ is not None and self.tag is not None
if has_header:
meth... | def _basic_debug(prefix, self) | Prints out basic information about an Asn1Value object. Extracted for reuse
among different classes that customize the debug information.
:param prefix:
A unicode string of spaces to prefix output line with
:param self:
The object to print the debugging information about | 2.680213 | 2.586795 | 1.036113 |
if 'tag_type' in params:
if params['tag_type'] == 'explicit':
params['explicit'] = (params.get('class', 2), params['tag'])
elif params['tag_type'] == 'implicit':
params['implicit'] = (params.get('class', 2), params['tag'])
del params['tag_type']
del para... | def _tag_type_to_explicit_implicit(params) | Converts old-style "tag_type" and "tag" params to "explicit" and "implicit"
:param params:
A dict of parameters to convert from tag_type/tag to explicit/implicit | 2.270038 | 2.244686 | 1.011294 |
_tag_type_to_explicit_implicit(params)
retag = False
if 'implicit' not in params:
if value.implicit is not False:
retag = True
else:
if isinstance(params['implicit'], tuple):
class_, tag = params['implicit']
else:
tag = params['implicit'... | def _fix_tagging(value, params) | Checks if a value is properly tagged based on the spec, and re/untags as
necessary
:param value:
An Asn1Value object
:param params:
A dict of spec params
:return:
An Asn1Value that is properly tagged | 4.349213 | 4.004079 | 1.086195 |
# Handle situations where the spec is not known at setup time
if spec is None:
return (None, None)
required_class = spec.class_
required_tag = spec.tag
_tag_type_to_explicit_implicit(params)
if 'explicit' in params:
if isinstance(params['explicit'], tuple):
r... | def _build_id_tuple(params, spec) | Builds a 2-element tuple used to identify fields by grabbing the class_
and tag from an Asn1Value class and the params dict being passed to it
:param params:
A dict of params to pass to spec
:param spec:
An Asn1Value class
:return:
A 2-element integer tuple in the form (class_... | 2.86558 | 2.584351 | 1.10882 |
encoded_len = len(encoded_data)
info, new_pointer = _parse(encoded_data, encoded_len, pointer)
if strict and new_pointer != pointer + encoded_len:
extra_bytes = pointer + encoded_len - new_pointer
raise ValueError('Extra data - %d bytes of trailing data were provided' % extra_bytes)
... | def _parse_build(encoded_data, pointer=0, spec=None, spec_params=None, strict=False) | Parses a byte string generically, or using a spec with optional params
:param encoded_data:
A byte string that contains BER-encoded data
:param pointer:
The index in the byte string to parse from
:param spec:
A class derived from Asn1Value that defines what class_ and tag the
... | 4.033727 | 4.056108 | 0.994482 |
new_obj = self.__class__()
new_obj.class_ = self.class_
new_obj.tag = self.tag
new_obj.implicit = self.implicit
new_obj.explicit = self.explicit
return new_obj | def _new_instance(self) | Constructs a new copy of the current object, preserving any tagging
:return:
An Asn1Value object | 4.535094 | 2.955637 | 1.534388 |
# This is required to preserve the old API
if not isinstance(tagging, dict):
tagging = {tagging: tag}
new_obj = self.__class__(explicit=tagging.get('explicit'), implicit=tagging.get('implicit'))
new_obj._copy(self, copy.deepcopy)
return new_obj | def retag(self, tagging, tag=None) | Copies the object, applying a new tagging to it
:param tagging:
A dict containing the keys "explicit" and "implicit". Legacy
API allows a unicode string of "implicit" or "explicit".
:param tag:
A integer tag number. Only used when tagging is a unicode string.
... | 5.718264 | 4.089169 | 1.398393 |
new_obj = self.__class__()
new_obj._copy(self, copy.deepcopy)
return new_obj | def untag(self) | Copies the object, removing any special tagging from it
:return:
An Asn1Value object | 11.570836 | 7.903033 | 1.464101 |
if self.__class__ != other.__class__:
raise TypeError(unwrap(
'''
Can not copy values from %s object to %s object
''',
type_name(other),
type_name(self)
))
self.contents = other.contents
... | def _copy(self, other, copy_func) | Copies the contents of another Asn1Value 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 | 4.523221 | 4.476891 | 1.010349 |
prefix = ' ' * nest_level
# This interacts with Any and moves the tag, implicit, explicit, _header,
# contents, _footer to the parsed value so duplicate data isn't present
has_parsed = hasattr(self, 'parsed')
_basic_debug(prefix, self)
if has_parsed:
... | def debug(self, nest_level=1) | Show the binary data and parsed data in a tree structure | 7.42379 | 7.056044 | 1.052118 |
contents = self.contents
if self._header is None or force:
if isinstance(self, Constructable) and self._indefinite:
self.method = 0
header = _dump_header(self.class_, self.method, self.tag, self.contents)
if self.explicit is not None:
... | def dump(self, force=False) | 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 | 5.757895 | 5.427898 | 1.060796 |
cls = self.__class__
if cls._map is None or cls._reverse_map is not None:
return
cls._reverse_map = {}
for key, value in cls._map.items():
cls._reverse_map[value] = key | def _setup(self) | Generates _reverse_map from _map | 3.405519 | 2.33429 | 1.45891 |
if other_class.tag != self.__class__.tag:
raise TypeError(unwrap(
'''
Can not covert a value from %s object to %s object since they
use different tags: %d versus %d
''',
type_name(other_class),
... | def cast(self, other_class) | Converts the current object into an object of a different class. The
new class must use the ASN.1 encoding for the value.
:param other_class:
The class to instantiate the new object from
:return:
An instance of the type other_class | 3.757854 | 3.308592 | 1.135787 |
if not self._indefinite:
return self._as_chunk()
pointer = self._chunks_offset
contents_len = len(self.contents)
output = None
while pointer < contents_len:
# We pass the current class as the spec so content semantics are preserved
... | def _merge_chunks(self) | :return:
A concatenation of the native values of the contained chunks | 5.968594 | 5.727485 | 1.042097 |
if self._chunks_offset == 0:
return self.contents
return self.contents[self._chunks_offset:] | def _as_chunk(self) | A method to return a chunk of data that can be combined for
constructed method values
:return:
A native Python value that can be added together. Examples include
byte strings, unicode strings or tuples. | 7.992477 | 6.725228 | 1.188432 |
super(Constructable, self)._copy(other, copy_func)
self.method = other.method
self._indefinite = other._indefinite | def _copy(self, other, copy_func) | Copies the contents of another Constructable 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 | 6.600653 | 5.857347 | 1.126901 |
if self._parsed is None or self._parsed[1:3] != (spec, spec_params):
try:
passed_params = spec_params or {}
_tag_type_to_explicit_implicit(passed_params)
if self.explicit is not None:
if 'explicit' in passed_params:
... | def parse(self, spec=None, spec_params=None) | Parses the contents generically, or using a spec with optional params
:param spec:
A class derived from Asn1Value that defines what class_ and tag the
value should have, and the semantics of the encoded value. The
return value will be of this type. If omitted, the encoded va... | 4.249132 | 3.912024 | 1.086172 |
super(Any, self)._copy(other, copy_func)
self._parsed = copy_func(other._parsed) | def _copy(self, other, copy_func) | Copies the contents of another Any 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 | 6.979352 | 5.633157 | 1.238977 |
if self._parsed is None:
self.parse()
return self._parsed[0].dump(force=force) | def dump(self, force=False) | 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 | 6.677338 | 5.422068 | 1.231511 |
if not isinstance(encoded_data, byte_cls):
raise TypeError('encoded_data must be a byte string, not %s' % type_name(encoded_data))
value, _ = _parse_build(encoded_data, spec=cls, spec_params=kwargs, strict=strict)
return value | def load(cls, encoded_data, strict=False, **kwargs) | Loads a BER/DER-encoded byte string using the current class as the spec
:param encoded_data:
A byte string of BER or DER encoded data
:param strict:
A boolean indicating if trailing data should be forbidden - if so, a
ValueError will be raised when trailing data exi... | 4.726273 | 4.575895 | 1.032863 |
cls = self.__class__
cls._id_map = {}
cls._name_map = {}
for index, info in enumerate(cls._alternatives):
if len(info) < 3:
info = info + ({},)
cls._alternatives[index] = info
id_ = _build_id_tuple(info[2], info[1])
... | def _setup(self) | Generates _id_map from _alternatives to allow validating contents | 3.691597 | 2.898061 | 1.273817 |
if not self._name:
self._name = self._alternatives[self._choice][0]
return self._name | def name(self) | :return:
A unicode string of the field name of the chosen alternative | 6.087773 | 3.907107 | 1.558128 |
if self._parsed is not None:
return self._parsed
try:
_, spec, params = self._alternatives[self._choice]
self._parsed, _ = _parse_build(self._contents, spec=spec, spec_params=params)
except (ValueError, TypeError) as e:
args = e.args[1:]... | def parse(self) | Parses the detected alternative
:return:
An Asn1Value object of the chosen alternative | 5.693285 | 4.964105 | 1.146891 |
id_ = (class_, tag)
if self.explicit is not None:
if self.explicit[-1] != id_:
raise ValueError(unwrap(
'''
%s was explicitly tagged, but the value provided does not
match the class and tag
... | def validate(self, class_, tag, contents) | Ensures that the class and tag specified exist as an alternative
:param class_:
The integer class_ from the encoded value header
:param tag:
The integer tag from the encoded value header
:param contents:
A byte string of the contents of the value - used whe... | 3.657295 | 3.382966 | 1.081091 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.