code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def _expand_subject_public_key_info(encoded):
"""Parse a SubjectPublicKeyInfo structure.
It returns a triple with:
* OID (string)
* encoded public key (bytes)
* Algorithm parameters (bytes or None)
"""
#
# SubjectPublicKeyInfo ::= SEQUENCE {
# algorithm Alg... | Parse a SubjectPublicKeyInfo structure.
It returns a triple with:
* OID (string)
* encoded public key (bytes)
* Algorithm parameters (bytes or None)
| _expand_subject_public_key_info | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/PublicKey/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/PublicKey/__init__.py | MIT |
def getrandbits(self, k):
"""Return a python long integer with k random bits."""
if self._randfunc is None:
self._randfunc = Random.new().read
mask = (1 << k) - 1
return mask & bytes_to_long(self._randfunc(ceil_div(k, 8))) | Return a python long integer with k random bits. | getrandbits | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Random/random.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Random/random.py | MIT |
def randrange(self, *args):
"""randrange([start,] stop[, step]):
Return a randomly-selected element from range(start, stop, step)."""
if len(args) == 3:
(start, stop, step) = args
elif len(args) == 2:
(start, stop) = args
step = 1
elif len(args... | randrange([start,] stop[, step]):
Return a randomly-selected element from range(start, stop, step). | randrange | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Random/random.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Random/random.py | MIT |
def choice(self, seq):
"""Return a random element from a (non-empty) sequence.
If the seqence is empty, raises IndexError.
"""
if len(seq) == 0:
raise IndexError("empty sequence")
return seq[self.randrange(len(seq))] | Return a random element from a (non-empty) sequence.
If the seqence is empty, raises IndexError.
| choice | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Random/random.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Random/random.py | MIT |
def sample(self, population, k):
"""Return a k-length list of unique elements chosen from the population sequence."""
num_choices = len(population)
if k > num_choices:
raise ValueError("sample larger than population")
retval = []
selected = {} # we emulate a set us... | Return a k-length list of unique elements chosen from the population sequence. | sample | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Random/random.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Random/random.py | MIT |
def load_tests(dir_comps, file_name, description, conversions):
"""Load and parse a test vector file
This function returnis a list of objects, one per group of adjacent
KV lines or for a single line in the form "[.*]".
For a group of lines, the object has one attribute per line.
"""
file_in =... | Load and parse a test vector file
This function returnis a list of objects, one per group of adjacent
KV lines or for a single line in the form "[.*]".
For a group of lines, the object has one attribute per line.
| load_tests | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/loader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/loader.py | MIT |
def strip_whitespace(s):
"""Remove whitespace from a text or byte string"""
if isinstance(s,str):
return b("".join(s.split()))
else:
return b("").join(s.split()) | Remove whitespace from a text or byte string | strip_whitespace | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/st_common.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/st_common.py | MIT |
def run(module=None, verbosity=0, stream=None, tests=None, config=None, **kwargs):
"""Execute self-tests.
This raises SelfTestError if any test is unsuccessful.
You may optionally pass in a sub-module of SelfTest if you only want to
perform some of the tests. For example, the following would test onl... | Execute self-tests.
This raises SelfTestError if any test is unsuccessful.
You may optionally pass in a sub-module of SelfTest if you only want to
perform some of the tests. For example, the following would test only the
hash modules:
Cryptodome.SelfTest.run(Cryptodome.SelfTest.Hash)
| run | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/__init__.py | MIT |
def _extract(d, k, default=_NoDefault):
"""Get an item from a dictionary, and remove it from the dictionary."""
try:
retval = d[k]
except KeyError:
if default is _NoDefault:
raise
return default
del d[k]
return retval | Get an item from a dictionary, and remove it from the dictionary. | _extract | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Cipher/common.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Cipher/common.py | MIT |
def test_eiter_encrypt_or_decrypt(self):
"""Verify that a cipher cannot be used for both decrypting and encrypting"""
c1 = ChaCha20.new(key=b("5") * 32, nonce=b("6") * 8)
c1.encrypt(b("8"))
self.assertRaises(TypeError, c1.decrypt, b("9"))
c2 = ChaCha20.new(key=b("5") * 32, nonc... | Verify that a cipher cannot be used for both decrypting and encrypting | test_eiter_encrypt_or_decrypt | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_ChaCha20.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_ChaCha20.py | MIT |
def test_streaming(self):
"""Verify that an arbitrary number of bytes can be encrypted/decrypted"""
from Cryptodome.Hash import SHA1
segments = (1, 3, 5, 7, 11, 17, 23)
total = sum(segments)
pt = b("")
while len(pt) < total:
pt += SHA1.new(pt).digest()
... | Verify that an arbitrary number of bytes can be encrypted/decrypted | test_streaming | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_ChaCha20.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_ChaCha20.py | MIT |
def rws(t):
"""Remove white spaces, tabs, and new lines from a string"""
for c in ['\n', '\t', ' ']:
t = t.replace(c,'')
return t | Remove white spaces, tabs, and new lines from a string | rws | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_pkcs1_15.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_pkcs1_15.py | MIT |
def t2b(t):
"""Convert a text string with bytes in hex form to a byte string"""
clean = b(rws(t))
if len(clean)%2 == 1:
print clean
raise ValueError("Even number of characters expected")
return a2b_hex(clean) | Convert a text string with bytes in hex form to a byte string | t2b | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_pkcs1_15.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_pkcs1_15.py | MIT |
def rws(t):
"""Remove white spaces, tabs, and new lines from a string"""
for c in ['\n', '\t', ' ']:
t = t.replace(c,'')
return t | Remove white spaces, tabs, and new lines from a string | rws | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_pkcs1_oaep.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_pkcs1_oaep.py | MIT |
def t2b(t):
"""Convert a text string with bytes in hex form to a byte string"""
clean = rws(t)
if len(clean)%2 == 1:
raise ValueError("Even number of characters expected")
return a2b_hex(clean) | Convert a text string with bytes in hex form to a byte string | t2b | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_pkcs1_oaep.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Cipher/test_pkcs1_oaep.py | MIT |
def __init__(self, hashmods):
"""Initialize the test with a dictionary of hash modules
indexed by their names"""
unittest.TestCase.__init__(self)
self.hashmods = hashmods
self.description = "" | Initialize the test with a dictionary of hash modules
indexed by their names | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Hash/test_HMAC.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Hash/test_HMAC.py | MIT |
def test2(self):
"""From draft-josefsson-scrypt-kdf-01, Chapter 10"""
output_1 = t2b("""
55 ac 04 6e 56 e3 08 9f ec 16 91 c2 25 44 b6 05
f9 41 85 21 6d de 04 65 e6 8b 9d 57 c2 0d ac bc
49 ca 9c cc f1 79 b6 45 99 16 64 b3 9d 77 ef 31
7c 71 b8 45 b1 e3 0b d5 09 11 20 41 d3... | From draft-josefsson-scrypt-kdf-01, Chapter 10 | test2 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Protocol/test_KDF.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Protocol/test_KDF.py | MIT |
def test2(self):
"""Verify that no more than 127(AES) and 63(TDES)
components are accepted."""
key = bchr(0) * 8 + bchr(255) * 8
for module in (AES, DES3):
s2v = _S2V.new(key, module)
max_comps = module.block_size*8-1
for i in xrange(max_comps):
... | Verify that no more than 127(AES) and 63(TDES)
components are accepted. | test2 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Protocol/test_KDF.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Protocol/test_KDF.py | MIT |
def runTest (self):
"Check converting English strings to keys"
for key, words in test_data:
key=binascii.a2b_hex(b(key))
self.assertEqual(RFC1751.english_to_key(words), key) | Check converting English strings to keys | runTest | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Protocol/test_rfc1751.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Protocol/test_rfc1751.py | MIT |
def _sws(s):
"""Remove whitespace from a text or byte string"""
if isinstance(s,str):
return "".join(s.split())
else:
return b("").join(s.split()) | Remove whitespace from a text or byte string | _sws | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | MIT |
def test_generate_1arg(self):
"""DSA (default implementation) generated key (1 argument)"""
dsaObj = self.dsa.generate(1024)
self._check_private_key(dsaObj)
pub = dsaObj.publickey()
self._check_public_key(pub) | DSA (default implementation) generated key (1 argument) | test_generate_1arg | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | MIT |
def test_generate_2arg(self):
"""DSA (default implementation) generated key (2 arguments)"""
dsaObj = self.dsa.generate(1024, Random.new().read)
self._check_private_key(dsaObj)
pub = dsaObj.publickey()
self._check_public_key(pub) | DSA (default implementation) generated key (2 arguments) | test_generate_2arg | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | MIT |
def test_construct_4tuple(self):
"""DSA (default implementation) constructed key (4-tuple)"""
(y, g, p, q) = [bytes_to_long(a2b_hex(param)) for param in (self.y, self.g, self.p, self.q)]
dsaObj = self.dsa.construct((y, g, p, q))
self._test_verification(dsaObj) | DSA (default implementation) constructed key (4-tuple) | test_construct_4tuple | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | MIT |
def test_construct_5tuple(self):
"""DSA (default implementation) constructed key (5-tuple)"""
(y, g, p, q, x) = [bytes_to_long(a2b_hex(param)) for param in (self.y, self.g, self.p, self.q, self.x)]
dsaObj = self.dsa.construct((y, g, p, q, x))
self._test_signing(dsaObj)
self._test... | DSA (default implementation) constructed key (5-tuple) | test_construct_5tuple | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | MIT |
def test_domain1(self):
"""Verify we can generate new keys in a given domain"""
dsa_key_1 = DSA.generate(1024)
domain_params = dsa_key_1.domain()
dsa_key_2 = DSA.generate(1024, domain=domain_params)
self.assertEqual(dsa_key_1.p, dsa_key_2.p)
self.assertEqual(dsa_key_1.q,... | Verify we can generate new keys in a given domain | test_domain1 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | MIT |
def test_generate_error_weak_domain(self):
"""Verify that domain parameters with composite q are rejected"""
domain_params = self._get_weak_domain()
self.assertRaises(ValueError, DSA.generate, 1024, domain=domain_params) | Verify that domain parameters with composite q are rejected | test_generate_error_weak_domain | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | MIT |
def test_construct_error_weak_domain(self):
"""Verify that domain parameters with composite q are rejected"""
from Cryptodome.Math.Numbers import Integer
p, q, g = self._get_weak_domain()
y = pow(g, 89, p)
self.assertRaises(ValueError, DSA.construct, (y, g, p, q)) | Verify that domain parameters with composite q are rejected | test_construct_error_weak_domain | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_DSA.py | MIT |
def convert_tv(self, tv, as_longs=0):
"""Convert a test vector from textual form (hexadecimal ascii
to either integers or byte strings."""
key_comps = 'p','g','y','x'
tv2 = {}
for c in tv.keys():
tv2[c] = a2b_hex(tv[c])
if as_longs or c in key_comps or c i... | Convert a test vector from textual form (hexadecimal ascii
to either integers or byte strings. | convert_tv | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_ElGamal.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_ElGamal.py | MIT |
def test_import_key(self):
"""Verify importKey is an alias to import_key"""
key_obj = DSA.import_key(self.der_public)
self.failIf(key_obj.has_private())
self.assertEqual(self.y, key_obj.y)
self.assertEqual(self.p, key_obj.p)
self.assertEqual(self.q, key_obj.q)
se... | Verify importKey is an alias to import_key | test_import_key | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_DSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_DSA.py | MIT |
def testImportKey1(self):
"""Verify import of RSAPrivateKey DER SEQUENCE"""
key = RSA.importKey(self.rsaKeyDER)
self.failUnless(key.has_private())
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e)
self.assertEqual(key.d, self.d)
self.assertEqual(key.... | Verify import of RSAPrivateKey DER SEQUENCE | testImportKey1 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey2(self):
"""Verify import of SubjectPublicKeyInfo DER SEQUENCE"""
key = RSA.importKey(self.rsaPublicKeyDER)
self.failIf(key.has_private())
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e) | Verify import of SubjectPublicKeyInfo DER SEQUENCE | testImportKey2 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey3unicode(self):
"""Verify import of RSAPrivateKey DER SEQUENCE, encoded with PEM as unicode"""
key = RSA.importKey(self.rsaKeyPEM)
self.assertEqual(key.has_private(),True) # assert_
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e)
self.asse... | Verify import of RSAPrivateKey DER SEQUENCE, encoded with PEM as unicode | testImportKey3unicode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey3bytes(self):
"""Verify import of RSAPrivateKey DER SEQUENCE, encoded with PEM as byte string"""
key = RSA.importKey(b(self.rsaKeyPEM))
self.assertEqual(key.has_private(),True) # assert_
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e)
self... | Verify import of RSAPrivateKey DER SEQUENCE, encoded with PEM as byte string | testImportKey3bytes | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey4unicode(self):
"""Verify import of RSAPrivateKey DER SEQUENCE, encoded with PEM as unicode"""
key = RSA.importKey(self.rsaPublicKeyPEM)
self.assertEqual(key.has_private(),False) # failIf
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e) | Verify import of RSAPrivateKey DER SEQUENCE, encoded with PEM as unicode | testImportKey4unicode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey4bytes(self):
"""Verify import of SubjectPublicKeyInfo DER SEQUENCE, encoded with PEM as byte string"""
key = RSA.importKey(b(self.rsaPublicKeyPEM))
self.assertEqual(key.has_private(),False) # failIf
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e) | Verify import of SubjectPublicKeyInfo DER SEQUENCE, encoded with PEM as byte string | testImportKey4bytes | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey5(self):
"""Verifies that the imported key is still a valid RSA pair"""
key = RSA.importKey(self.rsaKeyPEM)
idem = key._encrypt(key._decrypt(89L))
self.assertEqual(idem, 89L) | Verifies that the imported key is still a valid RSA pair | testImportKey5 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey6(self):
"""Verifies that the imported key is still a valid RSA pair"""
key = RSA.importKey(self.rsaKeyDER)
idem = key._encrypt(key._decrypt(65L))
self.assertEqual(idem, 65L) | Verifies that the imported key is still a valid RSA pair | testImportKey6 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey7(self):
"""Verify import of OpenSSH public key"""
key = RSA.importKey(self.rsaPublicKeyOpenSSH)
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e) | Verify import of OpenSSH public key | testImportKey7 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey8(self):
"""Verify import of encrypted PrivateKeyInfo DER SEQUENCE"""
for t in self.rsaKeyEncryptedPEM:
key = RSA.importKey(t[1], t[0])
self.failUnless(key.has_private())
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e)
... | Verify import of encrypted PrivateKeyInfo DER SEQUENCE | testImportKey8 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey9(self):
"""Verify import of unencrypted PrivateKeyInfo DER SEQUENCE"""
key = RSA.importKey(self.rsaKeyDER8)
self.failUnless(key.has_private())
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e)
self.assertEqual(key.d, self.d)
self.as... | Verify import of unencrypted PrivateKeyInfo DER SEQUENCE | testImportKey9 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey10(self):
"""Verify import of unencrypted PrivateKeyInfo DER SEQUENCE, encoded with PEM"""
key = RSA.importKey(self.rsaKeyPEM8)
self.failUnless(key.has_private())
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e)
self.assertEqual(key.d, self... | Verify import of unencrypted PrivateKeyInfo DER SEQUENCE, encoded with PEM | testImportKey10 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey11(self):
"""Verify import of RSAPublicKey DER SEQUENCE"""
der = asn1.DerSequence([17, 3]).encode()
key = RSA.importKey(der)
self.assertEqual(key.n, 17)
self.assertEqual(key.e, 3) | Verify import of RSAPublicKey DER SEQUENCE | testImportKey11 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def testImportKey12(self):
"""Verify import of RSAPublicKey DER SEQUENCE, encoded with PEM"""
der = asn1.DerSequence([17, 3]).encode()
pem = der2pem(der)
key = RSA.importKey(pem)
self.assertEqual(key.n, 17)
self.assertEqual(key.e, 3) | Verify import of RSAPublicKey DER SEQUENCE, encoded with PEM | testImportKey12 | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def test_import_key(self):
"""Verify that import_key is an alias to importKey"""
key = RSA.import_key(self.rsaPublicKeyDER)
self.failIf(key.has_private())
self.assertEqual(key.n, self.n)
self.assertEqual(key.e, self.e) | Verify that import_key is an alias to importKey | test_import_key | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_import_RSA.py | MIT |
def test_generate_1arg(self):
"""RSA (default implementation) generated key (1 argument)"""
rsaObj = self.rsa.generate(1024)
self._check_private_key(rsaObj)
self._exercise_primitive(rsaObj)
pub = rsaObj.publickey()
self._check_public_key(pub)
self._exercise_public... | RSA (default implementation) generated key (1 argument) | test_generate_1arg | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_RSA.py | MIT |
def test_generate_2arg(self):
"""RSA (default implementation) generated key (2 arguments)"""
rsaObj = self.rsa.generate(1024, Random.new().read)
self._check_private_key(rsaObj)
self._exercise_primitive(rsaObj)
pub = rsaObj.publickey()
self._check_public_key(pub)
s... | RSA (default implementation) generated key (2 arguments) | test_generate_2arg | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_RSA.py | MIT |
def test_construct_5tuple(self):
"""RSA (default implementation) constructed key (5-tuple)"""
rsaObj = self.rsa.construct((self.n, self.e, self.d, self.p, self.q))
self._check_private_key(rsaObj)
self._check_encryption(rsaObj)
self._check_decryption(rsaObj) | RSA (default implementation) constructed key (5-tuple) | test_construct_5tuple | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_RSA.py | MIT |
def test_construct_6tuple(self):
"""RSA (default implementation) constructed key (6-tuple)"""
rsaObj = self.rsa.construct((self.n, self.e, self.d, self.p, self.q, self.u))
self._check_private_key(rsaObj)
self._check_encryption(rsaObj)
self._check_decryption(rsaObj) | RSA (default implementation) constructed key (6-tuple) | test_construct_6tuple | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_RSA.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/PublicKey/test_RSA.py | MIT |
def test_negative_unapproved_hashes(self):
"""Verify that unapproved hashes are rejected"""
from Cryptodome.Hash import RIPEMD160
self.description = "Unapproved hash (RIPEMD160) test"
hash_obj = RIPEMD160.new()
signer = DSS.new(self.key_priv, 'fips-186-3')
self.assertRa... | Verify that unapproved hashes are rejected | test_negative_unapproved_hashes | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Signature/test_dss.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Signature/test_dss.py | MIT |
def test_negative_unknown_modes_encodings(self):
"""Verify that unknown modes/encodings are rejected"""
self.description = "Unknown mode test"
self.assertRaises(ValueError, DSS.new, self.key_priv, 'fips-186-0')
self.description = "Unknown encoding test"
self.assertRaises(ValueE... | Verify that unknown modes/encodings are rejected | test_negative_unknown_modes_encodings | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Signature/test_dss.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Signature/test_dss.py | MIT |
def test_negative_unapproved_hashes(self):
"""Verify that unapproved hashes are rejected"""
from Cryptodome.Hash import SHA1
self.description = "Unapproved hash (SHA-1) test"
hash_obj = SHA1.new()
signer = DSS.new(self.key_priv, 'fips-186-3')
self.assertRaises(ValueErro... | Verify that unapproved hashes are rejected | test_negative_unapproved_hashes | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/SelfTest/Signature/test_dss.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/SelfTest/Signature/test_dss.py | MIT |
def __init__(self, key, encoding, order):
"""Create a new Digital Signature Standard (DSS) object.
Do not instantiate this object directly,
use `Cryptodome.Signature.DSS.new` instead.
"""
self._key = key
self._encoding = encoding
self._order = order
sel... | Create a new Digital Signature Standard (DSS) object.
Do not instantiate this object directly,
use `Cryptodome.Signature.DSS.new` instead.
| __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/DSS.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/DSS.py | MIT |
def sign(self, msg_hash):
"""Produce the DSS signature of a message.
:Parameters:
msg_hash : hash object
The hash that was carried out over the message.
The object belongs to the `Cryptodome.Hash` package.
Under mode *'fips-186-3'*, the hash must be a FIPS... | Produce the DSS signature of a message.
:Parameters:
msg_hash : hash object
The hash that was carried out over the message.
The object belongs to the `Cryptodome.Hash` package.
Under mode *'fips-186-3'*, the hash must be a FIPS
approved secure hash (SH... | sign | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/DSS.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/DSS.py | MIT |
def verify(self, msg_hash, signature):
"""Verify that a certain DSS signature is authentic.
This function checks if the party holding the private half of the key
really signed the message.
:Parameters:
msg_hash : hash object
The hash that was carried out over the ... | Verify that a certain DSS signature is authentic.
This function checks if the party holding the private half of the key
really signed the message.
:Parameters:
msg_hash : hash object
The hash that was carried out over the message.
This is an object belonging t... | verify | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/DSS.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/DSS.py | MIT |
def _valid_hash(self, msg_hash):
"""Verify that SHA-[23] (256|384|512) bits are used to
match the 128-bit security of P-256"""
approved = ("2.16.840.1.101.3.4.2.1",
"2.16.840.1.101.3.4.2.2",
"2.16.840.1.101.3.4.2.3",
"2.16.840.1.101.3.... | Verify that SHA-[23] (256|384|512) bits are used to
match the 128-bit security of P-256 | _valid_hash | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/DSS.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/DSS.py | MIT |
def new(key, mode, encoding='binary', randfunc=None):
"""Return a signature scheme object `DSS_SigScheme` that
can be used to perform DSS signature or verification.
:Parameters:
key : a `Cryptodome.PublicKey.DSA` or `Cryptodome.PublicKey.ECC` key object
If the key has got its private half, bo... | Return a signature scheme object `DSS_SigScheme` that
can be used to perform DSS signature or verification.
:Parameters:
key : a `Cryptodome.PublicKey.DSA` or `Cryptodome.PublicKey.ECC` key object
If the key has got its private half, both signature and
verification are possible.
... | new | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/DSS.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/DSS.py | MIT |
def sign(self, msg_hash):
"""Produce the PKCS#1 v1.5 signature of a message.
This function is named ``RSASSA-PKCS1-V1_5-SIGN``;
it is specified in section 8.2.1 of RFC3447.
:Parameters:
msg_hash : hash object
This is an object created with to the `Cryptodome.Hash`... | Produce the PKCS#1 v1.5 signature of a message.
This function is named ``RSASSA-PKCS1-V1_5-SIGN``;
it is specified in section 8.2.1 of RFC3447.
:Parameters:
msg_hash : hash object
This is an object created with to the `Cryptodome.Hash` module.
It was used used... | sign | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/pkcs1_15.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/pkcs1_15.py | MIT |
def verify(self, msg_hash, signature):
"""Verify that a certain PKCS#1 v1.5 signature is valid.
This method checks if the message really originates from someone
that holds the RSA private key.
really signed the message.
This function is named ``RSASSA-PKCS1-V1_5-VERIFY``;
... | Verify that a certain PKCS#1 v1.5 signature is valid.
This method checks if the message really originates from someone
that holds the RSA private key.
really signed the message.
This function is named ``RSASSA-PKCS1-V1_5-VERIFY``;
it is specified in section 8.2.2 of RFC3447.
... | verify | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/pkcs1_15.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/pkcs1_15.py | MIT |
def _EMSA_PKCS1_V1_5_ENCODE(msg_hash, emLen, with_hash_parameters=True):
"""
Implement the ``EMSA-PKCS1-V1_5-ENCODE`` function, as defined
in PKCS#1 v2.1 (RFC3447, 9.2).
``_EMSA-PKCS1-V1_5-ENCODE`` actually accepts the message ``M`` as input,
and hash it internally. Here, we expect that the message... |
Implement the ``EMSA-PKCS1-V1_5-ENCODE`` function, as defined
in PKCS#1 v2.1 (RFC3447, 9.2).
``_EMSA-PKCS1-V1_5-ENCODE`` actually accepts the message ``M`` as input,
and hash it internally. Here, we expect that the message has already
been hashed instead.
:Parameters:
msg_hash : hash obj... | _EMSA_PKCS1_V1_5_ENCODE | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/pkcs1_15.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/pkcs1_15.py | MIT |
def __init__(self, key, mgfunc, saltLen, randfunc):
"""Initialize this PKCS#1 PSS signature scheme object.
:Parameters:
key : an RSA key object
If a private half is given, both signature and
verification are possible.
If a public half is given, only verific... | Initialize this PKCS#1 PSS signature scheme object.
:Parameters:
key : an RSA key object
If a private half is given, both signature and
verification are possible.
If a public half is given, only verification is possible.
mgfunc : callable
A ma... | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/pss.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/pss.py | MIT |
def sign(self, msg_hash):
"""Produce the PKCS#1 PSS signature of a message.
This function is named ``RSASSA-PSS-SIGN``, and is specified in
section 8.1.1 of RFC3447.
:Parameters:
msg_hash : hash object
The hash that was carried out over the message. This is an obj... | Produce the PKCS#1 PSS signature of a message.
This function is named ``RSASSA-PSS-SIGN``, and is specified in
section 8.1.1 of RFC3447.
:Parameters:
msg_hash : hash object
The hash that was carried out over the message. This is an object
belonging to the `Cry... | sign | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/pss.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/pss.py | MIT |
def verify(self, msg_hash, signature):
"""Verify that a certain PKCS#1 PSS signature is authentic.
This function checks if the party holding the private half
of the given RSA key has really signed the message.
This function is called ``RSASSA-PSS-VERIFY``, and is specified
in s... | Verify that a certain PKCS#1 PSS signature is authentic.
This function checks if the party holding the private half
of the given RSA key has really signed the message.
This function is called ``RSASSA-PSS-VERIFY``, and is specified
in section 8.1.2 of RFC3447.
:Parameters:
... | verify | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/pss.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/pss.py | MIT |
def _EMSA_PSS_ENCODE(mhash, emBits, randFunc, mgf, sLen):
"""
Implement the ``EMSA-PSS-ENCODE`` function, as defined
in PKCS#1 v2.1 (RFC3447, 9.1.1).
The original ``EMSA-PSS-ENCODE`` actually accepts the message ``M``
as input, and hash it internally. Here, we expect that the message
has alread... |
Implement the ``EMSA-PSS-ENCODE`` function, as defined
in PKCS#1 v2.1 (RFC3447, 9.1.1).
The original ``EMSA-PSS-ENCODE`` actually accepts the message ``M``
as input, and hash it internally. Here, we expect that the message
has already been hashed instead.
:Parameters:
mhash : hash objec... | _EMSA_PSS_ENCODE | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/pss.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/pss.py | MIT |
def _EMSA_PSS_VERIFY(mhash, em, emBits, mgf, sLen):
"""
Implement the ``EMSA-PSS-VERIFY`` function, as defined
in PKCS#1 v2.1 (RFC3447, 9.1.2).
``EMSA-PSS-VERIFY`` actually accepts the message ``M`` as input,
and hash it internally. Here, we expect that the message has already
been hashed inste... |
Implement the ``EMSA-PSS-VERIFY`` function, as defined
in PKCS#1 v2.1 (RFC3447, 9.1.2).
``EMSA-PSS-VERIFY`` actually accepts the message ``M`` as input,
and hash it internally. Here, we expect that the message has already
been hashed instead.
:Parameters:
mhash : hash object
The... | _EMSA_PSS_VERIFY | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/pss.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/pss.py | MIT |
def new(rsa_key, **kwargs):
"""Return a signature scheme object `PSS_SigScheme` that
can be used to perform PKCS#1 PSS signature or verification.
:Parameters:
rsa_key : RSA key object
The key to use to sign or verify the message.
This is a `Cryptodome.PublicKey.RSA` object.
Si... | Return a signature scheme object `PSS_SigScheme` that
can be used to perform PKCS#1 PSS signature or verification.
:Parameters:
rsa_key : RSA key object
The key to use to sign or verify the message.
This is a `Cryptodome.PublicKey.RSA` object.
Signing is only possible if *key* is ... | new | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Signature/pss.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Signature/pss.py | MIT |
def _convertTag(self, tag):
"""Check if *tag* is a real DER tag.
Convert it from a character to number if necessary.
"""
if not _is_number(tag):
if len(tag) == 1:
tag = bord(tag[0])
# Ensure that ... | Check if *tag* is a real DER tag.
Convert it from a character to number if necessary.
| _convertTag | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def _definite_form(length):
"""Build length octets according to BER/DER
definite form.
"""
if length > 127:
encoding = long_to_bytes(length)
return bchr(len(encoding) + 128) + encoding
return ... | Build length octets according to BER/DER
definite form.
| _definite_form | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def encode(self):
"""Return this DER element, fully encoded as a binary byte string."""
# Concatenate identifier octets, length octets,
# and contents octets
output_payload = self.payload
# In case of an EXTERNAL tag, first encode the in... | Return this DER element, fully encoded as a binary byte string. | encode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def _decodeLen(self, s):
"""Decode DER length octets from a file."""
length = s.read_byte()
if length <= 127:
return length
payloadLength = bytes_to_long(s.read(length & 0x7F))
# According to DER (but not BER) the l... | Decode DER length octets from a file. | _decodeLen | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def decode(self, derEle):
"""Decode a complete DER element, and re-initializes this
object with it.
:Parameters:
derEle : byte string
A complete DER element.
:Raise ValueError:
In case of parsing er... | Decode a complete DER element, and re-initializes this
object with it.
:Parameters:
derEle : byte string
A complete DER element.
:Raise ValueError:
In case of parsing errors.
| decode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def _decodeFromStream(self, s):
"""Decode a complete DER element from a file."""
idOctet = s.read_byte()
if self._tag_octet is not None:
if idOctet != self._tag_octet:
raise ValueError("Unexpected DER tag")
else... | Decode a complete DER element from a file. | _decodeFromStream | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def __init__(self, value=0, implicit=None, explicit=None):
"""Initialize the DER object as an INTEGER.
:Parameters:
value : integer
The value of the integer.
implicit : integer
The IMPLICIT tag to use for the e... | Initialize the DER object as an INTEGER.
:Parameters:
value : integer
The value of the integer.
implicit : integer
The IMPLICIT tag to use for the encoded object.
It overrides the universal tag for INTEGER ... | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def encode(self):
"""Return the DER INTEGER, fully encoded as a
binary string."""
number = self.value
self.payload = b('')
while True:
self.payload = bchr(int(number & 255)) + self.payload
if 128 <= ... | Return the DER INTEGER, fully encoded as a
binary string. | encode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def _decodeFromStream(self, s):
"""Decode a complete DER INTEGER from a file."""
# Fill up self.payload
DerObject._decodeFromStream(self, s)
# Derive self.value from self.payload
self.value = 0
bits = 1
for... | Decode a complete DER INTEGER from a file. | _decodeFromStream | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def __init__(self, startSeq=None, implicit=None):
"""Initialize the DER object as a SEQUENCE.
:Parameters:
startSeq : Python sequence
A sequence whose element are either integers or
other DER objects.
implicit ... | Initialize the DER object as a SEQUENCE.
:Parameters:
startSeq : Python sequence
A sequence whose element are either integers or
other DER objects.
implicit : integer
The IMPLICIT tag to use for the encoded... | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def hasInts(self, only_non_negative=True):
"""Return the number of items in this sequence that are
integers.
:Parameters:
only_non_negative : boolean
If True, negative integers are not counted in.
"""
... | Return the number of items in this sequence that are
integers.
:Parameters:
only_non_negative : boolean
If True, negative integers are not counted in.
| hasInts | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def encode(self):
"""Return this DER SEQUENCE, fully encoded as a
binary string.
:Raises ValueError:
If some elements in the sequence are neither integers
nor byte strings.
"""
self.payload = b('')
... | Return this DER SEQUENCE, fully encoded as a
binary string.
:Raises ValueError:
If some elements in the sequence are neither integers
nor byte strings.
| encode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def decode(self, derEle, nr_elements=None, only_ints_expected=False):
"""Decode a complete DER SEQUENCE, and re-initializes this
object with it.
:Parameters:
derEle : byte string
A complete SEQUENCE DER element.
nr_... | Decode a complete DER SEQUENCE, and re-initializes this
object with it.
:Parameters:
derEle : byte string
A complete SEQUENCE DER element.
nr_elements : None, integer or list of integers
The number of members th... | decode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def _decodeFromStream(self, s):
"""Decode a complete DER SEQUENCE from a file."""
self._seq = []
# Fill up self.payload
DerObject._decodeFromStream(self, s)
# Add one item at a time to self.seq, by scanning self.payload
p... | Decode a complete DER SEQUENCE from a file. | _decodeFromStream | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def __init__(self, value='', implicit=None, explicit=None):
"""Initialize the DER object as an OBJECT ID.
:Parameters:
value : string
The initial Object Identifier (e.g. "1.2.0.0.6.2").
implicit : integer
The IMPLICIT tag to use for the encoded object.
... | Initialize the DER object as an OBJECT ID.
:Parameters:
value : string
The initial Object Identifier (e.g. "1.2.0.0.6.2").
implicit : integer
The IMPLICIT tag to use for the encoded object.
It overrides the universal tag for OBJECT ID (6).
expli... | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def encode(self):
"""Return the DER OBJECT ID, fully encoded as a
binary string."""
comps = map(int, self.value.split("."))
if len(comps) < 2:
raise ValueError("Not a valid Object Identifier string")
self.payload = bchr(40*comps[0]+comps[1])
for v in comps[2:... | Return the DER OBJECT ID, fully encoded as a
binary string. | encode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def _decodeFromStream(self, s):
"""Decode a complete DER OBJECT ID from a file."""
# Fill up self.payload
DerObject._decodeFromStream(self, s)
# Derive self.value from self.payload
p = BytesIO_EOF(self.payload)
comps = list(map(str, divmod(p.read_byte(), 40)))
v... | Decode a complete DER OBJECT ID from a file. | _decodeFromStream | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def __init__(self, value=b(''), implicit=None, explicit=None):
"""Initialize the DER object as a BIT STRING.
:Parameters:
value : byte string or DER object
The initial, packed bit string.
If not specified, the bit string is empty.
implicit : integer
... | Initialize the DER object as a BIT STRING.
:Parameters:
value : byte string or DER object
The initial, packed bit string.
If not specified, the bit string is empty.
implicit : integer
The IMPLICIT tag to use for the encoded object.
It override... | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def encode(self):
"""Return the DER BIT STRING, fully encoded as a
binary string."""
# Add padding count byte
self.payload = b('\x00') + self.value
return DerObject.encode(self) | Return the DER BIT STRING, fully encoded as a
binary string. | encode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def _decodeFromStream(self, s):
"""Decode a complete DER BIT STRING DER from a file."""
# Fill-up self.payload
DerObject._decodeFromStream(self, s)
if self.payload and bord(self.payload[0]) != 0:
raise ValueError("Not a valid BIT STRING")
# Fill-up self.value
... | Decode a complete DER BIT STRING DER from a file. | _decodeFromStream | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def __init__(self, startSet=None, implicit=None):
"""Initialize the DER object as a SET OF.
:Parameters:
startSet : container
The initial set of integers or DER encoded objects.
implicit : integer
The IMPLICIT tag to use for the encoded object.
It... | Initialize the DER object as a SET OF.
:Parameters:
startSet : container
The initial set of integers or DER encoded objects.
implicit : integer
The IMPLICIT tag to use for the encoded object.
It overrides the universal tag for SET OF (17).
| __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def add(self, elem):
"""Add an element to the set.
:Parameters:
elem : byte string or integer
An element of the same type of objects already in the set.
It can be an integer or a DER encoded object.
"""
if _is_number(elem):
eo = 0x02
... | Add an element to the set.
:Parameters:
elem : byte string or integer
An element of the same type of objects already in the set.
It can be an integer or a DER encoded object.
| add | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def _decodeFromStream(self, s):
"""Decode a complete DER SET OF from a file."""
self._seq = []
# Fill up self.payload
DerObject._decodeFromStream(self, s)
# Add one item at a time to self.seq, by scanning self.payload
p = BytesIO_EOF(self.payload)
setIdOctet = ... | Decode a complete DER SET OF from a file. | _decodeFromStream | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def encode(self):
"""Return this SET OF DER element, fully encoded as a
binary string.
"""
# Elements in the set must be ordered in lexicographic order
ordered = []
for item in self._seq:
if _is_number(item):
bys = DerInteger(item).encode()
... | Return this SET OF DER element, fully encoded as a
binary string.
| encode | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/asn1.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/asn1.py | MIT |
def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, little_endian=False, allow_wraparound=False):
"""Create a stateful counter block function suitable for CTR encryption modes.
Each call to the function returns the next counter block.
Each counter block is made up by three parts::
prefix || ... | Create a stateful counter block function suitable for CTR encryption modes.
Each call to the function returns the next counter block.
Each counter block is made up by three parts::
prefix || counter value || postfix
The counter value is incremented by 1 at each call.
:Parameters:
nbits :... | new | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/Counter.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/Counter.py | MIT |
def size (N):
"""size(N:long) : int
Returns the size of the number N in bits.
"""
bits = 0
while N >> bits:
bits += 1
return bits | size(N:long) : int
Returns the size of the number N in bits.
| size | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/number.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/number.py | MIT |
def GCD(x,y):
"""GCD(x:long, y:long): long
Return the GCD of x and y.
"""
x = abs(x) ; y = abs(y)
while x > 0:
x, y = y % x, x
return y | GCD(x:long, y:long): long
Return the GCD of x and y.
| GCD | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/number.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/number.py | MIT |
def inverse(u, v):
"""inverse(u:long, v:long):long
Return the inverse of u mod v.
"""
u3, v3 = long(u), long(v)
u1, v1 = 1, 0
while v3 > 0:
q = u3 // v3
u1, v1 = v1, u1 - v1*q
u3, v3 = v3, u3 - v3*q
while u1<0:
u1 = u1 + v
return u1 | inverse(u:long, v:long):long
Return the inverse of u mod v.
| inverse | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/number.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/number.py | MIT |
def long_to_bytes(n, blocksize=0):
"""long_to_bytes(n:long, blocksize:int) : string
Convert a long integer to a byte string.
If optional blocksize is given and greater than zero, pad the front of the
byte string with binary zeros so that the length is a multiple of
blocksize.
"""
# after mu... | long_to_bytes(n:long, blocksize:int) : string
Convert a long integer to a byte string.
If optional blocksize is given and greater than zero, pad the front of the
byte string with binary zeros so that the length is a multiple of
blocksize.
| long_to_bytes | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/number.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/number.py | MIT |
def bytes_to_long(s):
"""bytes_to_long(string) : long
Convert a byte string to a long integer (big endian).
This is (essentially) the inverse of long_to_bytes().
"""
acc = 0
unpack = struct.unpack
length = len(s)
if length % 4:
extra = (4 - length % 4)
s = b('\000') * ex... | bytes_to_long(string) : long
Convert a byte string to a long integer (big endian).
This is (essentially) the inverse of long_to_bytes().
| bytes_to_long | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/number.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/number.py | MIT |
def _key2bin(s):
"Convert a key into a string of binary digits"
kl=map(lambda x: bord(x), s)
kl=map(lambda x: binary[x>>4]+binary[x&15], kl)
return ''.join(kl) | Convert a key into a string of binary digits | _key2bin | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/RFC1751.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/RFC1751.py | MIT |
def _extract(key, start, length):
"""Extract a bitstring(2.x)/bytestring(2.x) from a string of binary digits, and return its
numeric value."""
k=key[start:start+length]
return reduce(lambda x,y: x*2+ord(y)-48, k, 0) | Extract a bitstring(2.x)/bytestring(2.x) from a string of binary digits, and return its
numeric value. | _extract | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/RFC1751.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/RFC1751.py | MIT |
def key_to_english (key):
"""key_to_english(key:string(2.x)/bytes(3.x)) : string
Transform an arbitrary key into a string containing English words.
The key length must be a multiple of 8.
"""
english=''
for index in range(0, len(key), 8): # Loop over 8-byte subkeys
subkey=key[index:index... | key_to_english(key:string(2.x)/bytes(3.x)) : string
Transform an arbitrary key into a string containing English words.
The key length must be a multiple of 8.
| key_to_english | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/RFC1751.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/RFC1751.py | MIT |
def english_to_key (s):
"""english_to_key(string):string(2.x)/bytes(2.x)
Transform a string into a corresponding key.
The string must contain words separated by whitespace; the number
of words must be a multiple of 6.
"""
L=s.upper().split() ; key=b('')
for index in range(0, len(L), 6):
... | english_to_key(string):string(2.x)/bytes(2.x)
Transform a string into a corresponding key.
The string must contain words separated by whitespace; the number
of words must be a multiple of 6.
| english_to_key | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/RFC1751.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/RFC1751.py | MIT |
def strxor(term1, term2):
"""Return term1 xored with term2.
The two byte strings must have equal length."""
expect_byte_string(term1)
expect_byte_string(term2)
if len(term1) != len(term2):
raise ValueError("Only byte strings of equal length can be xored")
result = create_string_buffer(l... | Return term1 xored with term2.
The two byte strings must have equal length. | strxor | python | mchristopher/PokemonGo-DesktopMap | app/pylibs/win32/Cryptodome/Util/strxor.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pylibs/win32/Cryptodome/Util/strxor.py | MIT |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.