id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
8,900
Yubico/python-pyhsm
pyhsm/val/validation_server.py
ValOathDb.get
def get(self, key): """ Fetch entry from database. """ c = self.conn.cursor() for row in c.execute("SELECT key, nonce, key_handle, aead, oath_C, oath_T FROM oath WHERE key = ?", (key,)): return ValOathEntry(row) raise Exception("OATH token for '%s' not found in database (%s)"...
python
def get(self, key): """ Fetch entry from database. """ c = self.conn.cursor() for row in c.execute("SELECT key, nonce, key_handle, aead, oath_C, oath_T FROM oath WHERE key = ?", (key,)): return ValOathEntry(row) raise Exception("OATH token for '%s' not found in database (%s)"...
[ "def", "get", "(", "self", ",", "key", ")", ":", "c", "=", "self", ".", "conn", ".", "cursor", "(", ")", "for", "row", "in", "c", ".", "execute", "(", "\"SELECT key, nonce, key_handle, aead, oath_C, oath_T FROM oath WHERE key = ?\"", ",", "(", "key", ",", ")...
Fetch entry from database.
[ "Fetch", "entry", "from", "database", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L479-L484
8,901
Yubico/python-pyhsm
pyhsm/val/validation_server.py
ValOathDb.update_oath_hotp_c
def update_oath_hotp_c(self, entry, new_c): """ Update the OATH-HOTP counter value for `entry' in the database. Use SQL statement to ensure we only ever increase the counter. """ key = entry.data["key"] c = self.conn.cursor() c.execute("UPDATE oath SET oath_c = ?...
python
def update_oath_hotp_c(self, entry, new_c): """ Update the OATH-HOTP counter value for `entry' in the database. Use SQL statement to ensure we only ever increase the counter. """ key = entry.data["key"] c = self.conn.cursor() c.execute("UPDATE oath SET oath_c = ?...
[ "def", "update_oath_hotp_c", "(", "self", ",", "entry", ",", "new_c", ")", ":", "key", "=", "entry", ".", "data", "[", "\"key\"", "]", "c", "=", "self", ".", "conn", ".", "cursor", "(", ")", "c", ".", "execute", "(", "\"UPDATE oath SET oath_c = ? WHERE k...
Update the OATH-HOTP counter value for `entry' in the database. Use SQL statement to ensure we only ever increase the counter.
[ "Update", "the", "OATH", "-", "HOTP", "counter", "value", "for", "entry", "in", "the", "database", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L486-L497
8,902
Yubico/python-pyhsm
examples/yhsm-password-auth.py
generate_aead
def generate_aead(hsm, args, password): """ Generate an AEAD using the YubiHSM. """ try: pw = password.ljust(args.min_len, chr(0x0)) return hsm.generate_aead_simple(args.nonce.decode('hex'), args.key_handle, pw) except pyhsm.exception.YHSM_CommandFailed, e: if e.status_str ==...
python
def generate_aead(hsm, args, password): """ Generate an AEAD using the YubiHSM. """ try: pw = password.ljust(args.min_len, chr(0x0)) return hsm.generate_aead_simple(args.nonce.decode('hex'), args.key_handle, pw) except pyhsm.exception.YHSM_CommandFailed, e: if e.status_str ==...
[ "def", "generate_aead", "(", "hsm", ",", "args", ",", "password", ")", ":", "try", ":", "pw", "=", "password", ".", "ljust", "(", "args", ".", "min_len", ",", "chr", "(", "0x0", ")", ")", "return", "hsm", ".", "generate_aead_simple", "(", "args", "."...
Generate an AEAD using the YubiHSM.
[ "Generate", "an", "AEAD", "using", "the", "YubiHSM", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/examples/yhsm-password-auth.py#L108-L120
8,903
Yubico/python-pyhsm
pyhsm/tools/decrypt_aead.py
aead_filename
def aead_filename(aead_dir, key_handle, public_id): """ Return the filename of the AEAD for this public_id, and create any missing directorys. """ parts = [aead_dir, key_handle] + pyhsm.util.group(public_id, 2) path = os.path.join(*parts) if not os.path.isdir(path): os.makedirs(path...
python
def aead_filename(aead_dir, key_handle, public_id): """ Return the filename of the AEAD for this public_id, and create any missing directorys. """ parts = [aead_dir, key_handle] + pyhsm.util.group(public_id, 2) path = os.path.join(*parts) if not os.path.isdir(path): os.makedirs(path...
[ "def", "aead_filename", "(", "aead_dir", ",", "key_handle", ",", "public_id", ")", ":", "parts", "=", "[", "aead_dir", ",", "key_handle", "]", "+", "pyhsm", ".", "util", ".", "group", "(", "public_id", ",", "2", ")", "path", "=", "os", ".", "path", "...
Return the filename of the AEAD for this public_id, and create any missing directorys.
[ "Return", "the", "filename", "of", "the", "AEAD", "for", "this", "public_id", "and", "create", "any", "missing", "directorys", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/tools/decrypt_aead.py#L234-L245
8,904
Yubico/python-pyhsm
pyhsm/tools/decrypt_aead.py
safe_process_files
def safe_process_files(path, files, args, state): """ Process a number of files in a directory. Catches any exception from the processing and checks if we should fail directly or keep going. """ for fn in files: full_fn = os.path.join(path, fn) try: if not process_file(pa...
python
def safe_process_files(path, files, args, state): """ Process a number of files in a directory. Catches any exception from the processing and checks if we should fail directly or keep going. """ for fn in files: full_fn = os.path.join(path, fn) try: if not process_file(pa...
[ "def", "safe_process_files", "(", "path", ",", "files", ",", "args", ",", "state", ")", ":", "for", "fn", "in", "files", ":", "full_fn", "=", "os", ".", "path", ".", "join", "(", "path", ",", "fn", ")", "try", ":", "if", "not", "process_file", "(",...
Process a number of files in a directory. Catches any exception from the processing and checks if we should fail directly or keep going.
[ "Process", "a", "number", "of", "files", "in", "a", "directory", ".", "Catches", "any", "exception", "from", "the", "processing", "and", "checks", "if", "we", "should", "fail", "directly", "or", "keep", "going", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/tools/decrypt_aead.py#L247-L262
8,905
Yubico/python-pyhsm
pyhsm/tools/decrypt_aead.py
walk_dir
def walk_dir(path, args, state): """ Check all files in `path' to see if there is any requests that we should send out on the bus. """ if args.debug: sys.stderr.write("Walking %s\n" % path) for root, _dirs, files in os.walk(path): if not safe_process_files(root, files, args, sta...
python
def walk_dir(path, args, state): """ Check all files in `path' to see if there is any requests that we should send out on the bus. """ if args.debug: sys.stderr.write("Walking %s\n" % path) for root, _dirs, files in os.walk(path): if not safe_process_files(root, files, args, sta...
[ "def", "walk_dir", "(", "path", ",", "args", ",", "state", ")", ":", "if", "args", ".", "debug", ":", "sys", ".", "stderr", ".", "write", "(", "\"Walking %s\\n\"", "%", "path", ")", "for", "root", ",", "_dirs", ",", "files", "in", "os", ".", "walk"...
Check all files in `path' to see if there is any requests that we should send out on the bus.
[ "Check", "all", "files", "in", "path", "to", "see", "if", "there", "is", "any", "requests", "that", "we", "should", "send", "out", "on", "the", "bus", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/tools/decrypt_aead.py#L264-L277
8,906
Yubico/python-pyhsm
pyhsm/tools/decrypt_aead.py
main
def main(): """ Main function when running as a program. """ global args args = parse_args() if not args: return 1 state = MyState(args) for path in args.paths: if os.path.isdir(path): walk_dir(path, args, state) else: safe_process_files(os.path...
python
def main(): """ Main function when running as a program. """ global args args = parse_args() if not args: return 1 state = MyState(args) for path in args.paths: if os.path.isdir(path): walk_dir(path, args, state) else: safe_process_files(os.path...
[ "def", "main", "(", ")", ":", "global", "args", "args", "=", "parse_args", "(", ")", "if", "not", "args", ":", "return", "1", "state", "=", "MyState", "(", "args", ")", "for", "path", "in", "args", ".", "paths", ":", "if", "os", ".", "path", ".",...
Main function when running as a program.
[ "Main", "function", "when", "running", "as", "a", "program", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/tools/decrypt_aead.py#L279-L300
8,907
Yubico/python-pyhsm
pyhsm/oath_hotp.py
search_for_oath_code
def search_for_oath_code(hsm, key_handle, nonce, aead, counter, user_code, look_ahead=1): """ Try to validate an OATH HOTP OTP generated by a token whose secret key is available to the YubiHSM through the AEAD. The parameter `aead' is either a string, or an instance of YHSM_GeneratedAEAD. Returns ...
python
def search_for_oath_code(hsm, key_handle, nonce, aead, counter, user_code, look_ahead=1): """ Try to validate an OATH HOTP OTP generated by a token whose secret key is available to the YubiHSM through the AEAD. The parameter `aead' is either a string, or an instance of YHSM_GeneratedAEAD. Returns ...
[ "def", "search_for_oath_code", "(", "hsm", ",", "key_handle", ",", "nonce", ",", "aead", ",", "counter", ",", "user_code", ",", "look_ahead", "=", "1", ")", ":", "key_handle", "=", "pyhsm", ".", "util", ".", "input_validate_key_handle", "(", "key_handle", ")...
Try to validate an OATH HOTP OTP generated by a token whose secret key is available to the YubiHSM through the AEAD. The parameter `aead' is either a string, or an instance of YHSM_GeneratedAEAD. Returns next counter value on successful auth, and None otherwise.
[ "Try", "to", "validate", "an", "OATH", "HOTP", "OTP", "generated", "by", "a", "token", "whose", "secret", "key", "is", "available", "to", "the", "YubiHSM", "through", "the", "AEAD", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/oath_hotp.py#L20-L44
8,908
Yubico/python-pyhsm
pyhsm/oath_hotp.py
truncate
def truncate(hmac_result, length=6): """ Perform the truncating. """ assert(len(hmac_result) == 20) offset = ord(hmac_result[19]) & 0xf bin_code = (ord(hmac_result[offset]) & 0x7f) << 24 \ | (ord(hmac_result[offset+1]) & 0xff) << 16 \ | (ord(hmac_result[offset+2]) & 0xff) << 8 \ ...
python
def truncate(hmac_result, length=6): """ Perform the truncating. """ assert(len(hmac_result) == 20) offset = ord(hmac_result[19]) & 0xf bin_code = (ord(hmac_result[offset]) & 0x7f) << 24 \ | (ord(hmac_result[offset+1]) & 0xff) << 16 \ | (ord(hmac_result[offset+2]) & 0xff) << 8 \ ...
[ "def", "truncate", "(", "hmac_result", ",", "length", "=", "6", ")", ":", "assert", "(", "len", "(", "hmac_result", ")", "==", "20", ")", "offset", "=", "ord", "(", "hmac_result", "[", "19", "]", ")", "&", "0xf", "bin_code", "=", "(", "ord", "(", ...
Perform the truncating.
[ "Perform", "the", "truncating", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/oath_hotp.py#L46-L54
8,909
Yubico/python-pyhsm
pyhsm/stick.py
YHSM_Stick.flush
def flush(self): """ Flush input buffers. """ if self.debug: sys.stderr.write("%s: FLUSH INPUT (%i bytes waiting)\n" %( self.__class__.__name__, self.ser.inWaiting() )) self.ser.flushInput()
python
def flush(self): """ Flush input buffers. """ if self.debug: sys.stderr.write("%s: FLUSH INPUT (%i bytes waiting)\n" %( self.__class__.__name__, self.ser.inWaiting() )) self.ser.flushInput()
[ "def", "flush", "(", "self", ")", ":", "if", "self", ".", "debug", ":", "sys", ".", "stderr", ".", "write", "(", "\"%s: FLUSH INPUT (%i bytes waiting)\\n\"", "%", "(", "self", ".", "__class__", ".", "__name__", ",", "self", ".", "ser", ".", "inWaiting", ...
Flush input buffers.
[ "Flush", "input", "buffers", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/stick.py#L91-L100
8,910
Yubico/python-pyhsm
pyhsm/stick.py
YHSM_Stick.drain
def drain(self): """ Drain input. """ if self.debug: sys.stderr.write("%s: DRAIN INPUT (%i bytes waiting)\n" %( self.__class__.__name__, self.ser.inWaiting() )) old_timeout = self.ser.timeout self.ser.timeout = 0.1 ...
python
def drain(self): """ Drain input. """ if self.debug: sys.stderr.write("%s: DRAIN INPUT (%i bytes waiting)\n" %( self.__class__.__name__, self.ser.inWaiting() )) old_timeout = self.ser.timeout self.ser.timeout = 0.1 ...
[ "def", "drain", "(", "self", ")", ":", "if", "self", ".", "debug", ":", "sys", ".", "stderr", ".", "write", "(", "\"%s: DRAIN INPUT (%i bytes waiting)\\n\"", "%", "(", "self", ".", "__class__", ".", "__name__", ",", "self", ".", "ser", ".", "inWaiting", ...
Drain input.
[ "Drain", "input", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/stick.py#L102-L117
8,911
Yubico/python-pyhsm
pyhsm/ksm/db_import.py
extract_keyhandle
def extract_keyhandle(path, filepath): """extract keyhandle value from the path""" keyhandle = filepath.lstrip(path) keyhandle = keyhandle.split("/") return keyhandle[0]
python
def extract_keyhandle(path, filepath): """extract keyhandle value from the path""" keyhandle = filepath.lstrip(path) keyhandle = keyhandle.split("/") return keyhandle[0]
[ "def", "extract_keyhandle", "(", "path", ",", "filepath", ")", ":", "keyhandle", "=", "filepath", ".", "lstrip", "(", "path", ")", "keyhandle", "=", "keyhandle", ".", "split", "(", "\"/\"", ")", "return", "keyhandle", "[", "0", "]" ]
extract keyhandle value from the path
[ "extract", "keyhandle", "value", "from", "the", "path" ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/db_import.py#L19-L24
8,912
Yubico/python-pyhsm
pyhsm/ksm/db_import.py
insert_query
def insert_query(connection, publicId, aead, keyhandle, aeadobj): """this functions read the response fields and creates sql query. then inserts everything inside the database""" # turn the keyhandle into an integer keyhandle = key_handle_to_int(keyhandle) if not keyhandle == aead.key_handle: ...
python
def insert_query(connection, publicId, aead, keyhandle, aeadobj): """this functions read the response fields and creates sql query. then inserts everything inside the database""" # turn the keyhandle into an integer keyhandle = key_handle_to_int(keyhandle) if not keyhandle == aead.key_handle: ...
[ "def", "insert_query", "(", "connection", ",", "publicId", ",", "aead", ",", "keyhandle", ",", "aeadobj", ")", ":", "# turn the keyhandle into an integer", "keyhandle", "=", "key_handle_to_int", "(", "keyhandle", ")", "if", "not", "keyhandle", "==", "aead", ".", ...
this functions read the response fields and creates sql query. then inserts everything inside the database
[ "this", "functions", "read", "the", "response", "fields", "and", "creates", "sql", "query", ".", "then", "inserts", "everything", "inside", "the", "database" ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/db_import.py#L27-L45
8,913
Yubico/python-pyhsm
pyhsm/ksm/import_keys.py
import_keys
def import_keys(hsm, args): """ The main stdin iteration loop. """ res = True # ykksm 1 #123456,ftftftcccc,534543524554,fcacd309a20ce1809c2db257f0e8d6ea,000000000000,,, for line in sys.stdin: if line[0] == '#': continue l = line.split(',') modhex_id = l...
python
def import_keys(hsm, args): """ The main stdin iteration loop. """ res = True # ykksm 1 #123456,ftftftcccc,534543524554,fcacd309a20ce1809c2db257f0e8d6ea,000000000000,,, for line in sys.stdin: if line[0] == '#': continue l = line.split(',') modhex_id = l...
[ "def", "import_keys", "(", "hsm", ",", "args", ")", ":", "res", "=", "True", "# ykksm 1", "#123456,ftftftcccc,534543524554,fcacd309a20ce1809c2db257f0e8d6ea,000000000000,,,", "for", "line", "in", "sys", ".", "stdin", ":", "if", "line", "[", "0", "]", "==", "'#'", ...
The main stdin iteration loop.
[ "The", "main", "stdin", "iteration", "loop", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/import_keys.py#L142-L204
8,914
Yubico/python-pyhsm
pyhsm/ksm/import_keys.py
shorten_aead
def shorten_aead(aead): """ Produce pretty-printable version of long AEAD. """ head = aead.data[:4].encode('hex') tail = aead.data[-4:].encode('hex') return "%s...%s" % (head, tail)
python
def shorten_aead(aead): """ Produce pretty-printable version of long AEAD. """ head = aead.data[:4].encode('hex') tail = aead.data[-4:].encode('hex') return "%s...%s" % (head, tail)
[ "def", "shorten_aead", "(", "aead", ")", ":", "head", "=", "aead", ".", "data", "[", ":", "4", "]", ".", "encode", "(", "'hex'", ")", "tail", "=", "aead", ".", "data", "[", "-", "4", ":", "]", ".", "encode", "(", "'hex'", ")", "return", "\"%s.....
Produce pretty-printable version of long AEAD.
[ "Produce", "pretty", "-", "printable", "version", "of", "long", "AEAD", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/import_keys.py#L225-L229
8,915
Yubico/python-pyhsm
pyhsm/ksm/import_keys.py
output_filename
def output_filename(output_dir, key_handle, public_id): """ Return an output filename for a generated AEAD. Creates a hashed directory structure using the last three bytes of the public id to get equal usage. """ parts = [output_dir, key_handle] + pyhsm.util.group(public_id, 2) path = os.path.jo...
python
def output_filename(output_dir, key_handle, public_id): """ Return an output filename for a generated AEAD. Creates a hashed directory structure using the last three bytes of the public id to get equal usage. """ parts = [output_dir, key_handle] + pyhsm.util.group(public_id, 2) path = os.path.jo...
[ "def", "output_filename", "(", "output_dir", ",", "key_handle", ",", "public_id", ")", ":", "parts", "=", "[", "output_dir", ",", "key_handle", "]", "+", "pyhsm", ".", "util", ".", "group", "(", "public_id", ",", "2", ")", "path", "=", "os", ".", "path...
Return an output filename for a generated AEAD. Creates a hashed directory structure using the last three bytes of the public id to get equal usage.
[ "Return", "an", "output", "filename", "for", "a", "generated", "AEAD", ".", "Creates", "a", "hashed", "directory", "structure", "using", "the", "last", "three", "bytes", "of", "the", "public", "id", "to", "get", "equal", "usage", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/import_keys.py#L232-L243
8,916
Yubico/python-pyhsm
pyhsm/db_cmd.py
YHSM_Cmd_DB_YubiKey_Store.parse_result
def parse_result(self, data): """ Return True if the AEAD was stored sucessfully. """ # typedef struct { # uint8_t publicId[YSM_PUBLIC_ID_SIZE]; // Public id (nonce) # uint32_t keyHandle; // Key handle # YSM_STATUS status; // Validation stat...
python
def parse_result(self, data): """ Return True if the AEAD was stored sucessfully. """ # typedef struct { # uint8_t publicId[YSM_PUBLIC_ID_SIZE]; // Public id (nonce) # uint32_t keyHandle; // Key handle # YSM_STATUS status; // Validation stat...
[ "def", "parse_result", "(", "self", ",", "data", ")", ":", "# typedef struct {", "# uint8_t publicId[YSM_PUBLIC_ID_SIZE]; // Public id (nonce)", "# uint32_t keyHandle; // Key handle", "# YSM_STATUS status; // Validation status", "# } YSM_DB_YUBIKEY_AEAD...
Return True if the AEAD was stored sucessfully.
[ "Return", "True", "if", "the", "AEAD", "was", "stored", "sucessfully", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/db_cmd.py#L64-L81
8,917
Yubico/python-pyhsm
pyhsm/tools/generate_keys.py
gen_keys
def gen_keys(hsm, args): """ The main key generating loop. """ if args.verbose: print "Generating %i keys :\n" % (args.count) else: print "Generating %i keys" % (args.count) for int_id in range(args.start_id, args.start_id + args.count): public_id = ("%x" % int_id).rjus...
python
def gen_keys(hsm, args): """ The main key generating loop. """ if args.verbose: print "Generating %i keys :\n" % (args.count) else: print "Generating %i keys" % (args.count) for int_id in range(args.start_id, args.start_id + args.count): public_id = ("%x" % int_id).rjus...
[ "def", "gen_keys", "(", "hsm", ",", "args", ")", ":", "if", "args", ".", "verbose", ":", "print", "\"Generating %i keys :\\n\"", "%", "(", "args", ".", "count", ")", "else", ":", "print", "\"Generating %i keys\"", "%", "(", "args", ".", "count", ")", "fo...
The main key generating loop.
[ "The", "main", "key", "generating", "loop", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/tools/generate_keys.py#L135-L171
8,918
Yubico/python-pyhsm
pyhsm/cmd.py
reset
def reset(stick): """ Send a bunch of zero-bytes to the YubiHSM, and flush the input buffer. """ nulls = (pyhsm.defines.YSM_MAX_PKT_SIZE - 1) * '\x00' res = YHSM_Cmd(stick, pyhsm.defines.YSM_NULL, payload = nulls).execute(read_response = False) unlock = stick.acquire() try: stick.dra...
python
def reset(stick): """ Send a bunch of zero-bytes to the YubiHSM, and flush the input buffer. """ nulls = (pyhsm.defines.YSM_MAX_PKT_SIZE - 1) * '\x00' res = YHSM_Cmd(stick, pyhsm.defines.YSM_NULL, payload = nulls).execute(read_response = False) unlock = stick.acquire() try: stick.dra...
[ "def", "reset", "(", "stick", ")", ":", "nulls", "=", "(", "pyhsm", ".", "defines", ".", "YSM_MAX_PKT_SIZE", "-", "1", ")", "*", "'\\x00'", "res", "=", "YHSM_Cmd", "(", "stick", ",", "pyhsm", ".", "defines", ".", "YSM_NULL", ",", "payload", "=", "nul...
Send a bunch of zero-bytes to the YubiHSM, and flush the input buffer.
[ "Send", "a", "bunch", "of", "zero", "-", "bytes", "to", "the", "YubiHSM", "and", "flush", "the", "input", "buffer", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/cmd.py#L149-L161
8,919
Yubico/python-pyhsm
pyhsm/cmd.py
YHSM_Cmd.execute
def execute(self, read_response=True): """ Write command to HSM and read response. @param read_response: Whether to expect a response or not. @type read_response: bool """ # // Up- and downlink packet # typedef struct { # uint8_t bcnt; ...
python
def execute(self, read_response=True): """ Write command to HSM and read response. @param read_response: Whether to expect a response or not. @type read_response: bool """ # // Up- and downlink packet # typedef struct { # uint8_t bcnt; ...
[ "def", "execute", "(", "self", ",", "read_response", "=", "True", ")", ":", "# // Up- and downlink packet", "# typedef struct {", "# uint8_t bcnt; // Number of bytes (cmd + payload)", "# uint8_t cmd; // YSM_xxx command", "# uint8_t paylo...
Write command to HSM and read response. @param read_response: Whether to expect a response or not. @type read_response: bool
[ "Write", "command", "to", "HSM", "and", "read", "response", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/cmd.py#L47-L77
8,920
Yubico/python-pyhsm
pyhsm/cmd.py
YHSM_Cmd._read_response
def _read_response(self): """ After writing a command, read response. @returns: Result of parse_data() @raises pyhsm.exception.YHSM_Error: On failure to read a response to the command we sent in a timely fashion. """ # // Up- and downlink packet # ty...
python
def _read_response(self): """ After writing a command, read response. @returns: Result of parse_data() @raises pyhsm.exception.YHSM_Error: On failure to read a response to the command we sent in a timely fashion. """ # // Up- and downlink packet # ty...
[ "def", "_read_response", "(", "self", ")", ":", "# // Up- and downlink packet", "# typedef struct {", "# uint8_t bcnt; // Number of bytes (cmd + payload)", "# uint8_t cmd; // YSM_xxx command", "# uint8_t payload[YSM_MAX_PKT_SIZE]; // Payload", ...
After writing a command, read response. @returns: Result of parse_data() @raises pyhsm.exception.YHSM_Error: On failure to read a response to the command we sent in a timely fashion.
[ "After", "writing", "a", "command", "read", "response", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/cmd.py#L79-L117
8,921
Yubico/python-pyhsm
pyhsm/base.py
YHSM.reset
def reset(self, test_sync = True): """ Perform stream resynchronization. @param test_sync: Verify sync with YubiHSM after reset @type test_sync: bool @return: True if successful @rtype: bool """ pyhsm.cmd.reset(self.stick) if test_sync: ...
python
def reset(self, test_sync = True): """ Perform stream resynchronization. @param test_sync: Verify sync with YubiHSM after reset @type test_sync: bool @return: True if successful @rtype: bool """ pyhsm.cmd.reset(self.stick) if test_sync: ...
[ "def", "reset", "(", "self", ",", "test_sync", "=", "True", ")", ":", "pyhsm", ".", "cmd", ".", "reset", "(", "self", ".", "stick", ")", "if", "test_sync", ":", "# Now verify we are in sync", "data", "=", "'ekoeko'", "echo", "=", "self", ".", "echo", "...
Perform stream resynchronization. @param test_sync: Verify sync with YubiHSM after reset @type test_sync: bool @return: True if successful @rtype: bool
[ "Perform", "stream", "resynchronization", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L91-L110
8,922
Yubico/python-pyhsm
pyhsm/base.py
YHSM.set_debug
def set_debug(self, new): """ Set debug mode. @param new: new value @type new: bool @return: old value @rtype: bool """ if type(new) is not bool: raise pyhsm.exception.YHSM_WrongInputType( 'new', bool, type(new)) old =...
python
def set_debug(self, new): """ Set debug mode. @param new: new value @type new: bool @return: old value @rtype: bool """ if type(new) is not bool: raise pyhsm.exception.YHSM_WrongInputType( 'new', bool, type(new)) old =...
[ "def", "set_debug", "(", "self", ",", "new", ")", ":", "if", "type", "(", "new", ")", "is", "not", "bool", ":", "raise", "pyhsm", ".", "exception", ".", "YHSM_WrongInputType", "(", "'new'", ",", "bool", ",", "type", "(", "new", ")", ")", "old", "="...
Set debug mode. @param new: new value @type new: bool @return: old value @rtype: bool
[ "Set", "debug", "mode", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L112-L128
8,923
Yubico/python-pyhsm
pyhsm/base.py
YHSM.echo
def echo(self, data): """ Echo test. @type data: string @return: data read from YubiHSM -- should equal `data' @rtype: string @see: L{pyhsm.basic_cmd.YHSM_Cmd_Echo} """ return pyhsm.basic_cmd.YHSM_Cmd_Echo(self.stick, data).execute()
python
def echo(self, data): """ Echo test. @type data: string @return: data read from YubiHSM -- should equal `data' @rtype: string @see: L{pyhsm.basic_cmd.YHSM_Cmd_Echo} """ return pyhsm.basic_cmd.YHSM_Cmd_Echo(self.stick, data).execute()
[ "def", "echo", "(", "self", ",", "data", ")", ":", "return", "pyhsm", ".", "basic_cmd", ".", "YHSM_Cmd_Echo", "(", "self", ".", "stick", ",", "data", ")", ".", "execute", "(", ")" ]
Echo test. @type data: string @return: data read from YubiHSM -- should equal `data' @rtype: string @see: L{pyhsm.basic_cmd.YHSM_Cmd_Echo}
[ "Echo", "test", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L155-L165
8,924
Yubico/python-pyhsm
pyhsm/base.py
YHSM.random
def random(self, num_bytes): """ Get random bytes from YubiHSM. The random data is DRBG_CTR seeded on each startup by a hardware TRNG, so it should be of very good quality. @type num_bytes: integer @return: Bytes with random data @rtype: string @see: L...
python
def random(self, num_bytes): """ Get random bytes from YubiHSM. The random data is DRBG_CTR seeded on each startup by a hardware TRNG, so it should be of very good quality. @type num_bytes: integer @return: Bytes with random data @rtype: string @see: L...
[ "def", "random", "(", "self", ",", "num_bytes", ")", ":", "return", "pyhsm", ".", "basic_cmd", ".", "YHSM_Cmd_Random", "(", "self", ".", "stick", ",", "num_bytes", ")", ".", "execute", "(", ")" ]
Get random bytes from YubiHSM. The random data is DRBG_CTR seeded on each startup by a hardware TRNG, so it should be of very good quality. @type num_bytes: integer @return: Bytes with random data @rtype: string @see: L{pyhsm.basic_cmd.YHSM_Cmd_Random}
[ "Get", "random", "bytes", "from", "YubiHSM", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L177-L191
8,925
Yubico/python-pyhsm
pyhsm/base.py
YHSM.random_reseed
def random_reseed(self, seed): """ Provide YubiHSM DRBG_CTR with a new seed. @param seed: new seed -- must be exactly 32 bytes @type seed: string @returns: True on success @rtype: bool @see: L{pyhsm.basic_cmd.YHSM_Cmd_Random_Reseed} """ return p...
python
def random_reseed(self, seed): """ Provide YubiHSM DRBG_CTR with a new seed. @param seed: new seed -- must be exactly 32 bytes @type seed: string @returns: True on success @rtype: bool @see: L{pyhsm.basic_cmd.YHSM_Cmd_Random_Reseed} """ return p...
[ "def", "random_reseed", "(", "self", ",", "seed", ")", ":", "return", "pyhsm", ".", "basic_cmd", ".", "YHSM_Cmd_Random_Reseed", "(", "self", ".", "stick", ",", "seed", ")", ".", "execute", "(", ")" ]
Provide YubiHSM DRBG_CTR with a new seed. @param seed: new seed -- must be exactly 32 bytes @type seed: string @returns: True on success @rtype: bool @see: L{pyhsm.basic_cmd.YHSM_Cmd_Random_Reseed}
[ "Provide", "YubiHSM", "DRBG_CTR", "with", "a", "new", "seed", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L193-L205
8,926
Yubico/python-pyhsm
pyhsm/base.py
YHSM.get_nonce
def get_nonce(self, increment=1): """ Get current nonce from YubiHSM. Use increment 0 to just fetch the value without incrementing it. @keyword increment: requested increment (optional) @return: nonce value _before_ increment @rtype: L{YHSM_NonceResponse} @see...
python
def get_nonce(self, increment=1): """ Get current nonce from YubiHSM. Use increment 0 to just fetch the value without incrementing it. @keyword increment: requested increment (optional) @return: nonce value _before_ increment @rtype: L{YHSM_NonceResponse} @see...
[ "def", "get_nonce", "(", "self", ",", "increment", "=", "1", ")", ":", "return", "pyhsm", ".", "basic_cmd", ".", "YHSM_Cmd_Nonce_Get", "(", "self", ".", "stick", ",", "increment", ")", ".", "execute", "(", ")" ]
Get current nonce from YubiHSM. Use increment 0 to just fetch the value without incrementing it. @keyword increment: requested increment (optional) @return: nonce value _before_ increment @rtype: L{YHSM_NonceResponse} @see: L{pyhsm.basic_cmd.YHSM_Cmd_Nonce_Get}
[ "Get", "current", "nonce", "from", "YubiHSM", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L207-L220
8,927
Yubico/python-pyhsm
pyhsm/base.py
YHSM.load_temp_key
def load_temp_key(self, nonce, key_handle, aead): """ Load the contents of an AEAD into the phantom key handle 0xffffffff. @param nonce: The nonce used when creating the AEAD @param key_handle: The key handle that can decrypt the AEAD @param aead: AEAD containing the cryptograph...
python
def load_temp_key(self, nonce, key_handle, aead): """ Load the contents of an AEAD into the phantom key handle 0xffffffff. @param nonce: The nonce used when creating the AEAD @param key_handle: The key handle that can decrypt the AEAD @param aead: AEAD containing the cryptograph...
[ "def", "load_temp_key", "(", "self", ",", "nonce", ",", "key_handle", ",", "aead", ")", ":", "return", "pyhsm", ".", "basic_cmd", ".", "YHSM_Cmd_Temp_Key_Load", "(", "self", ".", "stick", ",", "nonce", ",", "key_handle", ",", "aead", ")", ".", "execute", ...
Load the contents of an AEAD into the phantom key handle 0xffffffff. @param nonce: The nonce used when creating the AEAD @param key_handle: The key handle that can decrypt the AEAD @param aead: AEAD containing the cryptographic key and permission flags @type nonce: string @type ...
[ "Load", "the", "contents", "of", "an", "AEAD", "into", "the", "phantom", "key", "handle", "0xffffffff", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L222-L238
8,928
Yubico/python-pyhsm
pyhsm/base.py
YHSM.load_secret
def load_secret(self, secret): """ Ask YubiHSM to load a pre-existing YubiKey secret. The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L{generate_aead} commands to actually retreive the generated secret ...
python
def load_secret(self, secret): """ Ask YubiHSM to load a pre-existing YubiKey secret. The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L{generate_aead} commands to actually retreive the generated secret ...
[ "def", "load_secret", "(", "self", ",", "secret", ")", ":", "if", "isinstance", "(", "secret", ",", "pyhsm", ".", "aead_cmd", ".", "YHSM_YubiKeySecret", ")", ":", "secret", "=", "secret", ".", "pack", "(", ")", "return", "pyhsm", ".", "buffer_cmd", ".", ...
Ask YubiHSM to load a pre-existing YubiKey secret. The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L{generate_aead} commands to actually retreive the generated secret (in encrypted form). @param secret: YubiKe...
[ "Ask", "YubiHSM", "to", "load", "a", "pre", "-", "existing", "YubiKey", "secret", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L294-L312
8,929
Yubico/python-pyhsm
pyhsm/base.py
YHSM.load_data
def load_data(self, data, offset): """ Ask YubiHSM to load arbitrary data into it's internal buffer, at any offset. The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L{generate_aead} commands to actually ...
python
def load_data(self, data, offset): """ Ask YubiHSM to load arbitrary data into it's internal buffer, at any offset. The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L{generate_aead} commands to actually ...
[ "def", "load_data", "(", "self", ",", "data", ",", "offset", ")", ":", "return", "pyhsm", ".", "buffer_cmd", ".", "YHSM_Cmd_Buffer_Load", "(", "self", ".", "stick", ",", "data", ",", "offset", ")", ".", "execute", "(", ")" ]
Ask YubiHSM to load arbitrary data into it's internal buffer, at any offset. The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L{generate_aead} commands to actually retreive the generated secret (in encrypted form). ...
[ "Ask", "YubiHSM", "to", "load", "arbitrary", "data", "into", "it", "s", "internal", "buffer", "at", "any", "offset", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L314-L332
8,930
Yubico/python-pyhsm
pyhsm/base.py
YHSM.load_random
def load_random(self, num_bytes, offset = 0): """ Ask YubiHSM to generate a number of random bytes to any offset of it's internal buffer. The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L{generate_aead}...
python
def load_random(self, num_bytes, offset = 0): """ Ask YubiHSM to generate a number of random bytes to any offset of it's internal buffer. The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L{generate_aead}...
[ "def", "load_random", "(", "self", ",", "num_bytes", ",", "offset", "=", "0", ")", ":", "return", "pyhsm", ".", "buffer_cmd", ".", "YHSM_Cmd_Buffer_Random_Load", "(", "self", ".", "stick", ",", "num_bytes", ",", "offset", ")", ".", "execute", "(", ")" ]
Ask YubiHSM to generate a number of random bytes to any offset of it's internal buffer. The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L{generate_aead} commands to actually retreive the generated secret (in en...
[ "Ask", "YubiHSM", "to", "generate", "a", "number", "of", "random", "bytes", "to", "any", "offset", "of", "it", "s", "internal", "buffer", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L334-L351
8,931
Yubico/python-pyhsm
pyhsm/base.py
YHSM.generate_aead_random
def generate_aead_random(self, nonce, key_handle, num_bytes): """ Generate a random AEAD block using the YubiHSM internal DRBG_CTR random generator. To generate a secret for a YubiKey, use public_id as nonce. @param nonce: The nonce to use when creating the AEAD @param key_hand...
python
def generate_aead_random(self, nonce, key_handle, num_bytes): """ Generate a random AEAD block using the YubiHSM internal DRBG_CTR random generator. To generate a secret for a YubiKey, use public_id as nonce. @param nonce: The nonce to use when creating the AEAD @param key_hand...
[ "def", "generate_aead_random", "(", "self", ",", "nonce", ",", "key_handle", ",", "num_bytes", ")", ":", "return", "pyhsm", ".", "aead_cmd", ".", "YHSM_Cmd_AEAD_Random_Generate", "(", "self", ".", "stick", ",", "nonce", ",", "key_handle", ",", "num_bytes", ")"...
Generate a random AEAD block using the YubiHSM internal DRBG_CTR random generator. To generate a secret for a YubiKey, use public_id as nonce. @param nonce: The nonce to use when creating the AEAD @param key_handle: The key handle that can encrypt the random data into an AEAD @param nu...
[ "Generate", "a", "random", "AEAD", "block", "using", "the", "YubiHSM", "internal", "DRBG_CTR", "random", "generator", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L372-L390
8,932
Yubico/python-pyhsm
pyhsm/base.py
YHSM.validate_aead_otp
def validate_aead_otp(self, public_id, otp, key_handle, aead): """ Ask YubiHSM to validate a YubiKey OTP using an AEAD and a key_handle to decrypt the AEAD. @param public_id: The six bytes public id of the YubiKey @param otp: The one time password (OTP) to validate @para...
python
def validate_aead_otp(self, public_id, otp, key_handle, aead): """ Ask YubiHSM to validate a YubiKey OTP using an AEAD and a key_handle to decrypt the AEAD. @param public_id: The six bytes public id of the YubiKey @param otp: The one time password (OTP) to validate @para...
[ "def", "validate_aead_otp", "(", "self", ",", "public_id", ",", "otp", ",", "key_handle", ",", "aead", ")", ":", "if", "type", "(", "public_id", ")", "is", "not", "str", ":", "assert", "(", ")", "if", "type", "(", "otp", ")", "is", "not", "str", ":...
Ask YubiHSM to validate a YubiKey OTP using an AEAD and a key_handle to decrypt the AEAD. @param public_id: The six bytes public id of the YubiKey @param otp: The one time password (OTP) to validate @param key_handle: The key handle that can decrypt the AEAD @param aead: AEAD co...
[ "Ask", "YubiHSM", "to", "validate", "a", "YubiKey", "OTP", "using", "an", "AEAD", "and", "a", "key_handle", "to", "decrypt", "the", "AEAD", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L436-L464
8,933
Yubico/python-pyhsm
pyhsm/base.py
YHSM.aes_ecb_encrypt
def aes_ecb_encrypt(self, key_handle, plaintext): """ AES ECB encrypt using a key handle. @warning: Please be aware of the known limitations of AES ECB mode before using it! @param key_handle: Key handle to use for AES ECB encryption @param plaintext: Data to encrypt @t...
python
def aes_ecb_encrypt(self, key_handle, plaintext): """ AES ECB encrypt using a key handle. @warning: Please be aware of the known limitations of AES ECB mode before using it! @param key_handle: Key handle to use for AES ECB encryption @param plaintext: Data to encrypt @t...
[ "def", "aes_ecb_encrypt", "(", "self", ",", "key_handle", ",", "plaintext", ")", ":", "return", "pyhsm", ".", "aes_ecb_cmd", ".", "YHSM_Cmd_AES_ECB_Encrypt", "(", "self", ".", "stick", ",", "key_handle", ",", "plaintext", ")", ".", "execute", "(", ")" ]
AES ECB encrypt using a key handle. @warning: Please be aware of the known limitations of AES ECB mode before using it! @param key_handle: Key handle to use for AES ECB encryption @param plaintext: Data to encrypt @type key_handle: integer or string @type plaintext: string ...
[ "AES", "ECB", "encrypt", "using", "a", "key", "handle", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L505-L522
8,934
Yubico/python-pyhsm
pyhsm/base.py
YHSM.aes_ecb_decrypt
def aes_ecb_decrypt(self, key_handle, ciphertext): """ AES ECB decrypt using a key handle. @warning: Please be aware of the known limitations of AES ECB mode before using it! @param key_handle: Key handle to use for AES ECB decryption @param ciphertext: Data to decrypt ...
python
def aes_ecb_decrypt(self, key_handle, ciphertext): """ AES ECB decrypt using a key handle. @warning: Please be aware of the known limitations of AES ECB mode before using it! @param key_handle: Key handle to use for AES ECB decryption @param ciphertext: Data to decrypt ...
[ "def", "aes_ecb_decrypt", "(", "self", ",", "key_handle", ",", "ciphertext", ")", ":", "return", "pyhsm", ".", "aes_ecb_cmd", ".", "YHSM_Cmd_AES_ECB_Decrypt", "(", "self", ".", "stick", ",", "key_handle", ",", "ciphertext", ")", ".", "execute", "(", ")" ]
AES ECB decrypt using a key handle. @warning: Please be aware of the known limitations of AES ECB mode before using it! @param key_handle: Key handle to use for AES ECB decryption @param ciphertext: Data to decrypt @type key_handle: integer or string @type ciphertext: string ...
[ "AES", "ECB", "decrypt", "using", "a", "key", "handle", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L524-L541
8,935
Yubico/python-pyhsm
pyhsm/base.py
YHSM.aes_ecb_compare
def aes_ecb_compare(self, key_handle, ciphertext, plaintext): """ AES ECB decrypt and then compare using a key handle. The comparison is done inside the YubiHSM so the plaintext is never exposed (well, except indirectionally when the provided plaintext does match). @warning: Pl...
python
def aes_ecb_compare(self, key_handle, ciphertext, plaintext): """ AES ECB decrypt and then compare using a key handle. The comparison is done inside the YubiHSM so the plaintext is never exposed (well, except indirectionally when the provided plaintext does match). @warning: Pl...
[ "def", "aes_ecb_compare", "(", "self", ",", "key_handle", ",", "ciphertext", ",", "plaintext", ")", ":", "return", "pyhsm", ".", "aes_ecb_cmd", ".", "YHSM_Cmd_AES_ECB_Compare", "(", "self", ".", "stick", ",", "key_handle", ",", "ciphertext", ",", "plaintext", ...
AES ECB decrypt and then compare using a key handle. The comparison is done inside the YubiHSM so the plaintext is never exposed (well, except indirectionally when the provided plaintext does match). @warning: Please be aware of the known limitations of AES ECB mode before using it! @...
[ "AES", "ECB", "decrypt", "and", "then", "compare", "using", "a", "key", "handle", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L543-L563
8,936
Yubico/python-pyhsm
pyhsm/base.py
YHSM.hmac_sha1
def hmac_sha1(self, key_handle, data, flags = None, final = True, to_buffer = False): """ Have the YubiHSM generate a HMAC SHA1 of 'data' using a key handle. Use the L{pyhsm.hmac_cmd.YHSM_Cmd_HMAC_SHA1_Write.next} to add more input (until 'final' has been set to True). Use the ...
python
def hmac_sha1(self, key_handle, data, flags = None, final = True, to_buffer = False): """ Have the YubiHSM generate a HMAC SHA1 of 'data' using a key handle. Use the L{pyhsm.hmac_cmd.YHSM_Cmd_HMAC_SHA1_Write.next} to add more input (until 'final' has been set to True). Use the ...
[ "def", "hmac_sha1", "(", "self", ",", "key_handle", ",", "data", ",", "flags", "=", "None", ",", "final", "=", "True", ",", "to_buffer", "=", "False", ")", ":", "return", "pyhsm", ".", "hmac_cmd", ".", "YHSM_Cmd_HMAC_SHA1_Write", "(", "self", ".", "stick...
Have the YubiHSM generate a HMAC SHA1 of 'data' using a key handle. Use the L{pyhsm.hmac_cmd.YHSM_Cmd_HMAC_SHA1_Write.next} to add more input (until 'final' has been set to True). Use the L{pyhsm.hmac_cmd.YHSM_Cmd_HMAC_SHA1_Write.get_hash} to get the hash result this far. @par...
[ "Have", "the", "YubiHSM", "generate", "a", "HMAC", "SHA1", "of", "data", "using", "a", "key", "handle", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L568-L593
8,937
Yubico/python-pyhsm
pyhsm/base.py
YHSM.db_validate_yubikey_otp
def db_validate_yubikey_otp(self, public_id, otp): """ Request the YubiHSM to validate an OTP for a YubiKey stored in the internal database. @param public_id: The six bytes public id of the YubiKey @param otp: The OTP from a YubiKey in binary form (16 bytes) @type public...
python
def db_validate_yubikey_otp(self, public_id, otp): """ Request the YubiHSM to validate an OTP for a YubiKey stored in the internal database. @param public_id: The six bytes public id of the YubiKey @param otp: The OTP from a YubiKey in binary form (16 bytes) @type public...
[ "def", "db_validate_yubikey_otp", "(", "self", ",", "public_id", ",", "otp", ")", ":", "return", "pyhsm", ".", "db_cmd", ".", "YHSM_Cmd_DB_Validate_OTP", "(", "self", ".", "stick", ",", "public_id", ",", "otp", ")", ".", "execute", "(", ")" ]
Request the YubiHSM to validate an OTP for a YubiKey stored in the internal database. @param public_id: The six bytes public id of the YubiKey @param otp: The OTP from a YubiKey in binary form (16 bytes) @type public_id: string @type otp: string @returns: validation res...
[ "Request", "the", "YubiHSM", "to", "validate", "an", "OTP", "for", "a", "YubiKey", "stored", "in", "the", "internal", "database", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/base.py#L626-L642
8,938
Yubico/python-pyhsm
pyhsm/ksm/yubikey_ksm.py
aead_filename
def aead_filename(aead_dir, key_handle, public_id): """ Return the filename of the AEAD for this public_id. """ parts = [aead_dir, key_handle] + pyhsm.util.group(public_id, 2) + [public_id] return os.path.join(*parts)
python
def aead_filename(aead_dir, key_handle, public_id): """ Return the filename of the AEAD for this public_id. """ parts = [aead_dir, key_handle] + pyhsm.util.group(public_id, 2) + [public_id] return os.path.join(*parts)
[ "def", "aead_filename", "(", "aead_dir", ",", "key_handle", ",", "public_id", ")", ":", "parts", "=", "[", "aead_dir", ",", "key_handle", "]", "+", "pyhsm", ".", "util", ".", "group", "(", "public_id", ",", "2", ")", "+", "[", "public_id", "]", "return...
Return the filename of the AEAD for this public_id.
[ "Return", "the", "filename", "of", "the", "AEAD", "for", "this", "public_id", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/yubikey_ksm.py#L249-L254
8,939
Yubico/python-pyhsm
pyhsm/ksm/yubikey_ksm.py
run
def run(hsm, aead_backend, args): """ Start a BaseHTTPServer.HTTPServer and serve requests forever. """ write_pid_file(args.pid_file) server_address = (args.listen_addr, args.listen_port) httpd = YHSM_KSMServer(server_address, partial(YHSM_KSMRequestHandler, hsm, aea...
python
def run(hsm, aead_backend, args): """ Start a BaseHTTPServer.HTTPServer and serve requests forever. """ write_pid_file(args.pid_file) server_address = (args.listen_addr, args.listen_port) httpd = YHSM_KSMServer(server_address, partial(YHSM_KSMRequestHandler, hsm, aea...
[ "def", "run", "(", "hsm", ",", "aead_backend", ",", "args", ")", ":", "write_pid_file", "(", "args", ".", "pid_file", ")", "server_address", "=", "(", "args", ".", "listen_addr", ",", "args", ".", "listen_port", ")", "httpd", "=", "YHSM_KSMServer", "(", ...
Start a BaseHTTPServer.HTTPServer and serve requests forever.
[ "Start", "a", "BaseHTTPServer", ".", "HTTPServer", "and", "serve", "requests", "forever", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/yubikey_ksm.py#L394-L407
8,940
Yubico/python-pyhsm
pyhsm/ksm/yubikey_ksm.py
my_log_message
def my_log_message(verbose, prio, msg): """ Log to syslog, and possibly also to stderr. """ syslog.syslog(prio, msg) if verbose or prio == syslog.LOG_ERR: sys.stderr.write("%s\n" % (msg))
python
def my_log_message(verbose, prio, msg): """ Log to syslog, and possibly also to stderr. """ syslog.syslog(prio, msg) if verbose or prio == syslog.LOG_ERR: sys.stderr.write("%s\n" % (msg))
[ "def", "my_log_message", "(", "verbose", ",", "prio", ",", "msg", ")", ":", "syslog", ".", "syslog", "(", "prio", ",", "msg", ")", "if", "verbose", "or", "prio", "==", "syslog", ".", "LOG_ERR", ":", "sys", ".", "stderr", ".", "write", "(", "\"%s\\n\"...
Log to syslog, and possibly also to stderr.
[ "Log", "to", "syslog", "and", "possibly", "also", "to", "stderr", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/yubikey_ksm.py#L410-L416
8,941
Yubico/python-pyhsm
pyhsm/ksm/yubikey_ksm.py
YHSM_KSMRequestHandler.do_GET
def do_GET(self): """ Handle a HTTP GET request. """ # Example session: # in : GET /wsapi/decrypt?otp=ftftftccccdvvbfcfduvvcubikngtchlubtutucrld HTTP/1.0 # out : OK counter=0004 low=f585 high=3e use=03 if self.path.startswith(self.serve_url): from_key = self.path[len...
python
def do_GET(self): """ Handle a HTTP GET request. """ # Example session: # in : GET /wsapi/decrypt?otp=ftftftccccdvvbfcfduvvcubikngtchlubtutucrld HTTP/1.0 # out : OK counter=0004 low=f585 high=3e use=03 if self.path.startswith(self.serve_url): from_key = self.path[len...
[ "def", "do_GET", "(", "self", ")", ":", "# Example session:", "# in : GET /wsapi/decrypt?otp=ftftftccccdvvbfcfduvvcubikngtchlubtutucrld HTTP/1.0", "# out : OK counter=0004 low=f585 high=3e use=03", "if", "self", ".", "path", ".", "startswith", "(", "self", ".", "serve_url", ")...
Handle a HTTP GET request.
[ "Handle", "a", "HTTP", "GET", "request", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/yubikey_ksm.py#L92-L116
8,942
Yubico/python-pyhsm
pyhsm/ksm/yubikey_ksm.py
YHSM_KSMRequestHandler.decrypt_yubikey_otp
def decrypt_yubikey_otp(self, from_key): """ Try to decrypt a YubiKey OTP. Returns a string starting with either 'OK' or 'ERR' : 'OK counter=ab12 low=dd34 high=2a use=0a' 'ERR Unknown public_id' on YubiHSM errors (or bad OTP), only 'ERR' is returned. """ ...
python
def decrypt_yubikey_otp(self, from_key): """ Try to decrypt a YubiKey OTP. Returns a string starting with either 'OK' or 'ERR' : 'OK counter=ab12 low=dd34 high=2a use=0a' 'ERR Unknown public_id' on YubiHSM errors (or bad OTP), only 'ERR' is returned. """ ...
[ "def", "decrypt_yubikey_otp", "(", "self", ",", "from_key", ")", ":", "if", "not", "re", ".", "match", "(", "valid_input_from_key", ",", "from_key", ")", ":", "self", ".", "log_error", "(", "\"IN: %s, Invalid OTP\"", "%", "(", "from_key", ")", ")", "if", "...
Try to decrypt a YubiKey OTP. Returns a string starting with either 'OK' or 'ERR' : 'OK counter=ab12 low=dd34 high=2a use=0a' 'ERR Unknown public_id' on YubiHSM errors (or bad OTP), only 'ERR' is returned.
[ "Try", "to", "decrypt", "a", "YubiKey", "OTP", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/yubikey_ksm.py#L118-L162
8,943
Yubico/python-pyhsm
pyhsm/ksm/yubikey_ksm.py
YHSM_KSMRequestHandler.my_address_string
def my_address_string(self): """ For logging client host without resolving. """ addr = getattr(self, 'client_address', ('', None))[0] # If listed in proxy_ips, use the X-Forwarded-For header, if present. if addr in self.proxy_ips: return self.headers.getheader('x-forwarded-f...
python
def my_address_string(self): """ For logging client host without resolving. """ addr = getattr(self, 'client_address', ('', None))[0] # If listed in proxy_ips, use the X-Forwarded-For header, if present. if addr in self.proxy_ips: return self.headers.getheader('x-forwarded-f...
[ "def", "my_address_string", "(", "self", ")", ":", "addr", "=", "getattr", "(", "self", ",", "'client_address'", ",", "(", "''", ",", "None", ")", ")", "[", "0", "]", "# If listed in proxy_ips, use the X-Forwarded-For header, if present.", "if", "addr", "in", "s...
For logging client host without resolving.
[ "For", "logging", "client", "host", "without", "resolving", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/yubikey_ksm.py#L174-L181
8,944
Yubico/python-pyhsm
pyhsm/ksm/yubikey_ksm.py
SQLBackend.load_aead
def load_aead(self, public_id): """ Loads AEAD from the specified database. """ connection = self.engine.connect() trans = connection.begin() try: s = sqlalchemy.select([self.aead_table]).where( (self.aead_table.c.public_id == public_id) & sel...
python
def load_aead(self, public_id): """ Loads AEAD from the specified database. """ connection = self.engine.connect() trans = connection.begin() try: s = sqlalchemy.select([self.aead_table]).where( (self.aead_table.c.public_id == public_id) & sel...
[ "def", "load_aead", "(", "self", ",", "public_id", ")", ":", "connection", "=", "self", ".", "engine", ".", "connect", "(", ")", "trans", "=", "connection", ".", "begin", "(", ")", "try", ":", "s", "=", "sqlalchemy", ".", "select", "(", "[", "self", ...
Loads AEAD from the specified database.
[ "Loads", "AEAD", "from", "the", "specified", "database", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/ksm/yubikey_ksm.py#L215-L236
8,945
Yubico/python-pyhsm
pyhsm/val/init_oath_token.py
generate_aead
def generate_aead(hsm, args): """ Protect the oath-k in an AEAD. """ key = get_oath_k(args) # Enabled flags 00010000 = YSM_HMAC_SHA1_GENERATE flags = struct.pack("< I", 0x10000) hsm.load_secret(key + flags) nonce = hsm.get_nonce().nonce aead = hsm.generate_aead(nonce, args.key_handle) if...
python
def generate_aead(hsm, args): """ Protect the oath-k in an AEAD. """ key = get_oath_k(args) # Enabled flags 00010000 = YSM_HMAC_SHA1_GENERATE flags = struct.pack("< I", 0x10000) hsm.load_secret(key + flags) nonce = hsm.get_nonce().nonce aead = hsm.generate_aead(nonce, args.key_handle) if...
[ "def", "generate_aead", "(", "hsm", ",", "args", ")", ":", "key", "=", "get_oath_k", "(", "args", ")", "# Enabled flags 00010000 = YSM_HMAC_SHA1_GENERATE", "flags", "=", "struct", ".", "pack", "(", "\"< I\"", ",", "0x10000", ")", "hsm", ".", "load_secret", "("...
Protect the oath-k in an AEAD.
[ "Protect", "the", "oath", "-", "k", "in", "an", "AEAD", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/init_oath_token.py#L105-L115
8,946
Yubico/python-pyhsm
pyhsm/val/init_oath_token.py
store_oath_entry
def store_oath_entry(args, nonce, aead, oath_c): """ Store the AEAD in the database. """ data = {"key": args.uid, "aead": aead.data.encode('hex'), "nonce": nonce.encode('hex'), "key_handle": args.key_handle, "oath_C": oath_c, "oath_T": None, ...
python
def store_oath_entry(args, nonce, aead, oath_c): """ Store the AEAD in the database. """ data = {"key": args.uid, "aead": aead.data.encode('hex'), "nonce": nonce.encode('hex'), "key_handle": args.key_handle, "oath_C": oath_c, "oath_T": None, ...
[ "def", "store_oath_entry", "(", "args", ",", "nonce", ",", "aead", ",", "oath_c", ")", ":", "data", "=", "{", "\"key\"", ":", "args", ".", "uid", ",", "\"aead\"", ":", "aead", ".", "data", ".", "encode", "(", "'hex'", ")", ",", "\"nonce\"", ":", "n...
Store the AEAD in the database.
[ "Store", "the", "AEAD", "in", "the", "database", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/init_oath_token.py#L185-L203
8,947
Yubico/python-pyhsm
pyhsm/val/init_oath_token.py
ValOathDb.add
def add(self, entry): """ Add entry to database. """ c = self.conn.cursor() c.execute("INSERT INTO oath (key, aead, nonce, key_handle, oath_C, oath_T) VALUES (?, ?, ?, ?, ?, ?)", (entry.data["key"], \ entry.data["aead"], \ entry.dat...
python
def add(self, entry): """ Add entry to database. """ c = self.conn.cursor() c.execute("INSERT INTO oath (key, aead, nonce, key_handle, oath_C, oath_T) VALUES (?, ?, ?, ?, ?, ?)", (entry.data["key"], \ entry.data["aead"], \ entry.dat...
[ "def", "add", "(", "self", ",", "entry", ")", ":", "c", "=", "self", ".", "conn", ".", "cursor", "(", ")", "c", ".", "execute", "(", "\"INSERT INTO oath (key, aead, nonce, key_handle, oath_C, oath_T) VALUES (?, ?, ?, ?, ?, ?)\"", ",", "(", "entry", ".", "data", ...
Add entry to database.
[ "Add", "entry", "to", "database", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/init_oath_token.py#L161-L172
8,948
Yubico/python-pyhsm
pyhsm/val/init_oath_token.py
ValOathDb.delete
def delete(self, entry): """ Delete entry from database. """ c = self.conn.cursor() c.execute("DELETE FROM oath WHERE key = ?", (entry.data["key"],))
python
def delete(self, entry): """ Delete entry from database. """ c = self.conn.cursor() c.execute("DELETE FROM oath WHERE key = ?", (entry.data["key"],))
[ "def", "delete", "(", "self", ",", "entry", ")", ":", "c", "=", "self", ".", "conn", ".", "cursor", "(", ")", "c", ".", "execute", "(", "\"DELETE FROM oath WHERE key = ?\"", ",", "(", "entry", ".", "data", "[", "\"key\"", "]", ",", ")", ")" ]
Delete entry from database.
[ "Delete", "entry", "from", "database", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/init_oath_token.py#L174-L177
8,949
Yubico/python-pyhsm
pyhsm/aead_cmd.py
YHSM_AEAD_Cmd.parse_result
def parse_result(self, data): """ Returns a YHSM_GeneratedAEAD instance, or throws pyhsm.exception.YHSM_CommandFailed. """ # typedef struct { # uint8_t nonce[YSM_AEAD_NONCE_SIZE]; // Nonce (publicId for Yubikey AEADs) # uint32_t keyHandle; // Key handl...
python
def parse_result(self, data): """ Returns a YHSM_GeneratedAEAD instance, or throws pyhsm.exception.YHSM_CommandFailed. """ # typedef struct { # uint8_t nonce[YSM_AEAD_NONCE_SIZE]; // Nonce (publicId for Yubikey AEADs) # uint32_t keyHandle; // Key handl...
[ "def", "parse_result", "(", "self", ",", "data", ")", ":", "# typedef struct {", "# uint8_t nonce[YSM_AEAD_NONCE_SIZE]; // Nonce (publicId for Yubikey AEADs)", "# uint32_t keyHandle; // Key handle", "# YSM_STATUS status; // Status", "# uint8_t numByte...
Returns a YHSM_GeneratedAEAD instance, or throws pyhsm.exception.YHSM_CommandFailed.
[ "Returns", "a", "YHSM_GeneratedAEAD", "instance", "or", "throws", "pyhsm", ".", "exception", ".", "YHSM_CommandFailed", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/aead_cmd.py#L58-L84
8,950
Yubico/python-pyhsm
pyhsm/aead_cmd.py
YHSM_GeneratedAEAD.save
def save(self, filename): """ Store AEAD in a file. @param filename: File to create/overwrite @type filename: string """ aead_f = open(filename, "wb") fmt = "< B I %is %is" % (pyhsm.defines.YSM_AEAD_NONCE_SIZE, len(self.data)) version = 1 packed =...
python
def save(self, filename): """ Store AEAD in a file. @param filename: File to create/overwrite @type filename: string """ aead_f = open(filename, "wb") fmt = "< B I %is %is" % (pyhsm.defines.YSM_AEAD_NONCE_SIZE, len(self.data)) version = 1 packed =...
[ "def", "save", "(", "self", ",", "filename", ")", ":", "aead_f", "=", "open", "(", "filename", ",", "\"wb\"", ")", "fmt", "=", "\"< B I %is %is\"", "%", "(", "pyhsm", ".", "defines", ".", "YSM_AEAD_NONCE_SIZE", ",", "len", "(", "self", ".", "data", ")"...
Store AEAD in a file. @param filename: File to create/overwrite @type filename: string
[ "Store", "AEAD", "in", "a", "file", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/aead_cmd.py#L214-L226
8,951
Yubico/python-pyhsm
pyhsm/aead_cmd.py
YHSM_GeneratedAEAD.load
def load(self, filename): """ Load AEAD from a file. @param filename: File to read AEAD from @type filename: string """ aead_f = open(filename, "rb") buf = aead_f.read(1024) if buf.startswith(YHSM_AEAD_CRLF_File_Marker): buf = YHSM_AEAD_File_M...
python
def load(self, filename): """ Load AEAD from a file. @param filename: File to read AEAD from @type filename: string """ aead_f = open(filename, "rb") buf = aead_f.read(1024) if buf.startswith(YHSM_AEAD_CRLF_File_Marker): buf = YHSM_AEAD_File_M...
[ "def", "load", "(", "self", ",", "filename", ")", ":", "aead_f", "=", "open", "(", "filename", ",", "\"rb\"", ")", "buf", "=", "aead_f", ".", "read", "(", "1024", ")", "if", "buf", ".", "startswith", "(", "YHSM_AEAD_CRLF_File_Marker", ")", ":", "buf", ...
Load AEAD from a file. @param filename: File to read AEAD from @type filename: string
[ "Load", "AEAD", "from", "a", "file", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/aead_cmd.py#L228-L250
8,952
Yubico/python-pyhsm
pyhsm/aead_cmd.py
YHSM_YubiKeySecret.pack
def pack(self): """ Return key and uid packed for sending in a command to the YubiHSM. """ # # 22-bytes Yubikey secrets block # typedef struct { # uint8_t key[KEY_SIZE]; // AES key # uint8_t uid[UID_SIZE]; // Unique (secret) ID # } YUBIKEY_SE...
python
def pack(self): """ Return key and uid packed for sending in a command to the YubiHSM. """ # # 22-bytes Yubikey secrets block # typedef struct { # uint8_t key[KEY_SIZE]; // AES key # uint8_t uid[UID_SIZE]; // Unique (secret) ID # } YUBIKEY_SE...
[ "def", "pack", "(", "self", ")", ":", "# # 22-bytes Yubikey secrets block", "# typedef struct {", "# uint8_t key[KEY_SIZE]; // AES key", "# uint8_t uid[UID_SIZE]; // Unique (secret) ID", "# } YUBIKEY_SECRETS;", "return", "self", ".", "key", "+", "self", ...
Return key and uid packed for sending in a command to the YubiHSM.
[ "Return", "key", "and", "uid", "packed", "for", "sending", "in", "a", "command", "to", "the", "YubiHSM", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/aead_cmd.py#L258-L265
8,953
Yubico/python-pyhsm
pyhsm/val/validate_otp.py
validate_otp
def validate_otp(hsm, args): """ Validate an OTP. """ try: res = pyhsm.yubikey.validate_otp(hsm, args.otp) if args.verbose: print "OK counter=%04x low=%04x high=%02x use=%02x" % \ (res.use_ctr, res.ts_low, res.ts_high, res.session_ctr) return 0 exc...
python
def validate_otp(hsm, args): """ Validate an OTP. """ try: res = pyhsm.yubikey.validate_otp(hsm, args.otp) if args.verbose: print "OK counter=%04x low=%04x high=%02x use=%02x" % \ (res.use_ctr, res.ts_low, res.ts_high, res.session_ctr) return 0 exc...
[ "def", "validate_otp", "(", "hsm", ",", "args", ")", ":", "try", ":", "res", "=", "pyhsm", ".", "yubikey", ".", "validate_otp", "(", "hsm", ",", "args", ".", "otp", ")", "if", "args", ".", "verbose", ":", "print", "\"OK counter=%04x low=%04x high=%02x use=...
Validate an OTP.
[ "Validate", "an", "OTP", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validate_otp.py#L61-L81
8,954
Yubico/python-pyhsm
pyhsm/oath_totp.py
search_for_oath_code
def search_for_oath_code(hsm, key_handle, nonce, aead, user_code, interval=30, tolerance=0): """ Try to validate an OATH TOTP OTP generated by a token whose secret key is available to the YubiHSM through the AEAD. The parameter `aead' is either a string, or an instance of YHSM_...
python
def search_for_oath_code(hsm, key_handle, nonce, aead, user_code, interval=30, tolerance=0): """ Try to validate an OATH TOTP OTP generated by a token whose secret key is available to the YubiHSM through the AEAD. The parameter `aead' is either a string, or an instance of YHSM_...
[ "def", "search_for_oath_code", "(", "hsm", ",", "key_handle", ",", "nonce", ",", "aead", ",", "user_code", ",", "interval", "=", "30", ",", "tolerance", "=", "0", ")", ":", "# timecounter is the lowest acceptable value based on tolerance", "timecounter", "=", "timec...
Try to validate an OATH TOTP OTP generated by a token whose secret key is available to the YubiHSM through the AEAD. The parameter `aead' is either a string, or an instance of YHSM_GeneratedAEAD. Returns timecounter value on successful auth, and None otherwise.
[ "Try", "to", "validate", "an", "OATH", "TOTP", "OTP", "generated", "by", "a", "token", "whose", "secret", "key", "is", "available", "to", "the", "YubiHSM", "through", "the", "AEAD", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/oath_totp.py#L21-L36
8,955
Yubico/python-pyhsm
pyhsm/oath_totp.py
timecode
def timecode(time_now, interval): """ make integer and divide by time interval of valid OTP """ i = time.mktime(time_now.timetuple()) return int(i / interval)
python
def timecode(time_now, interval): """ make integer and divide by time interval of valid OTP """ i = time.mktime(time_now.timetuple()) return int(i / interval)
[ "def", "timecode", "(", "time_now", ",", "interval", ")", ":", "i", "=", "time", ".", "mktime", "(", "time_now", ".", "timetuple", "(", ")", ")", "return", "int", "(", "i", "/", "interval", ")" ]
make integer and divide by time interval of valid OTP
[ "make", "integer", "and", "divide", "by", "time", "interval", "of", "valid", "OTP" ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/oath_totp.py#L39-L42
8,956
Yubico/python-pyhsm
pyhsm/soft_hsm.py
_xor_block
def _xor_block(a, b): """ XOR two blocks of equal length. """ return ''.join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b)])
python
def _xor_block(a, b): """ XOR two blocks of equal length. """ return ''.join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b)])
[ "def", "_xor_block", "(", "a", ",", "b", ")", ":", "return", "''", ".", "join", "(", "[", "chr", "(", "ord", "(", "x", ")", "^", "ord", "(", "y", ")", ")", "for", "(", "x", ",", "y", ")", "in", "zip", "(", "a", ",", "b", ")", "]", ")" ]
XOR two blocks of equal length.
[ "XOR", "two", "blocks", "of", "equal", "length", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/soft_hsm.py#L26-L28
8,957
Yubico/python-pyhsm
pyhsm/soft_hsm.py
crc16
def crc16(data): """ Calculate an ISO13239 CRC checksum of the input buffer. """ m_crc = 0xffff for this in data: m_crc ^= ord(this) for _ in range(8): j = m_crc & 1 m_crc >>= 1 if j: m_crc ^= 0x8408 return m_crc
python
def crc16(data): """ Calculate an ISO13239 CRC checksum of the input buffer. """ m_crc = 0xffff for this in data: m_crc ^= ord(this) for _ in range(8): j = m_crc & 1 m_crc >>= 1 if j: m_crc ^= 0x8408 return m_crc
[ "def", "crc16", "(", "data", ")", ":", "m_crc", "=", "0xffff", "for", "this", "in", "data", ":", "m_crc", "^=", "ord", "(", "this", ")", "for", "_", "in", "range", "(", "8", ")", ":", "j", "=", "m_crc", "&", "1", "m_crc", ">>=", "1", "if", "j...
Calculate an ISO13239 CRC checksum of the input buffer.
[ "Calculate", "an", "ISO13239", "CRC", "checksum", "of", "the", "input", "buffer", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/soft_hsm.py#L132-L144
8,958
Yubico/python-pyhsm
pyhsm/soft_hsm.py
_cbc_mac.finalize
def finalize(self, block): """ The final step of CBC-MAC encrypts before xor. """ t1 = self.mac_aes.encrypt(block) t2 = _xor_block(self.mac, t1) self.mac = t2
python
def finalize(self, block): """ The final step of CBC-MAC encrypts before xor. """ t1 = self.mac_aes.encrypt(block) t2 = _xor_block(self.mac, t1) self.mac = t2
[ "def", "finalize", "(", "self", ",", "block", ")", ":", "t1", "=", "self", ".", "mac_aes", ".", "encrypt", "(", "block", ")", "t2", "=", "_xor_block", "(", "self", ".", "mac", ",", "t1", ")", "self", ".", "mac", "=", "t2" ]
The final step of CBC-MAC encrypts before xor.
[ "The", "final", "step", "of", "CBC", "-", "MAC", "encrypts", "before", "xor", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/soft_hsm.py#L77-L83
8,959
Yubico/python-pyhsm
pyhsm/yubikey.py
validate_otp
def validate_otp(hsm, from_key): """ Try to validate an OTP from a YubiKey using the internal database on the YubiHSM. `from_key' is the modhex encoded string emitted when you press the button on your YubiKey. Will only return on succesfull validation. All failures will result in an L{pyhs...
python
def validate_otp(hsm, from_key): """ Try to validate an OTP from a YubiKey using the internal database on the YubiHSM. `from_key' is the modhex encoded string emitted when you press the button on your YubiKey. Will only return on succesfull validation. All failures will result in an L{pyhs...
[ "def", "validate_otp", "(", "hsm", ",", "from_key", ")", ":", "public_id", ",", "otp", "=", "split_id_otp", "(", "from_key", ")", "return", "hsm", ".", "db_validate_yubikey_otp", "(", "modhex_decode", "(", "public_id", ")", ".", "decode", "(", "'hex'", ")", ...
Try to validate an OTP from a YubiKey using the internal database on the YubiHSM. `from_key' is the modhex encoded string emitted when you press the button on your YubiKey. Will only return on succesfull validation. All failures will result in an L{pyhsm.exception.YHSM_CommandFailed}. @param ...
[ "Try", "to", "validate", "an", "OTP", "from", "a", "YubiKey", "using", "the", "internal", "database", "on", "the", "YubiHSM", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/yubikey.py#L24-L48
8,960
Yubico/python-pyhsm
pyhsm/yubikey.py
validate_yubikey_with_aead
def validate_yubikey_with_aead(hsm, from_key, aead, key_handle): """ Try to validate an OTP from a YubiKey using the AEAD that can decrypt this YubiKey's internal secret, using the key_handle for the AEAD. `from_key' is the modhex encoded string emitted when you press the button on your YubiKey. ...
python
def validate_yubikey_with_aead(hsm, from_key, aead, key_handle): """ Try to validate an OTP from a YubiKey using the AEAD that can decrypt this YubiKey's internal secret, using the key_handle for the AEAD. `from_key' is the modhex encoded string emitted when you press the button on your YubiKey. ...
[ "def", "validate_yubikey_with_aead", "(", "hsm", ",", "from_key", ",", "aead", ",", "key_handle", ")", ":", "from_key", "=", "pyhsm", ".", "util", ".", "input_validate_str", "(", "from_key", ",", "'from_key'", ",", "max_len", "=", "48", ")", "nonce", "=", ...
Try to validate an OTP from a YubiKey using the AEAD that can decrypt this YubiKey's internal secret, using the key_handle for the AEAD. `from_key' is the modhex encoded string emitted when you press the button on your YubiKey. Will only return on succesfull validation. All failures will result in...
[ "Try", "to", "validate", "an", "OTP", "from", "a", "YubiKey", "using", "the", "AEAD", "that", "can", "decrypt", "this", "YubiKey", "s", "internal", "secret", "using", "the", "key_handle", "for", "the", "AEAD", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/yubikey.py#L50-L90
8,961
Yubico/python-pyhsm
pyhsm/yubikey.py
split_id_otp
def split_id_otp(from_key): """ Separate public id from OTP given a YubiKey OTP as input. @param from_key: The OTP from a YubiKey (in modhex) @type from_key: string @returns: public_id and OTP @rtype: tuple of string """ if len(from_key) > 32: public_id, otp = from_key[:-32], f...
python
def split_id_otp(from_key): """ Separate public id from OTP given a YubiKey OTP as input. @param from_key: The OTP from a YubiKey (in modhex) @type from_key: string @returns: public_id and OTP @rtype: tuple of string """ if len(from_key) > 32: public_id, otp = from_key[:-32], f...
[ "def", "split_id_otp", "(", "from_key", ")", ":", "if", "len", "(", "from_key", ")", ">", "32", ":", "public_id", ",", "otp", "=", "from_key", "[", ":", "-", "32", "]", ",", "from_key", "[", "-", "32", ":", "]", "elif", "len", "(", "from_key", ")...
Separate public id from OTP given a YubiKey OTP as input. @param from_key: The OTP from a YubiKey (in modhex) @type from_key: string @returns: public_id and OTP @rtype: tuple of string
[ "Separate", "public", "id", "from", "OTP", "given", "a", "YubiKey", "OTP", "as", "input", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/yubikey.py#L118-L136
8,962
Yubico/python-pyhsm
pyhsm/tools/keystore_unlock.py
get_password
def get_password(hsm, args): """ Get password of correct length for this YubiHSM version. """ expected_len = 32 name = 'HSM password' if hsm.version.have_key_store_decrypt(): expected_len = 64 name = 'master key' if args.stdin: password = sys.stdin.readline() while p...
python
def get_password(hsm, args): """ Get password of correct length for this YubiHSM version. """ expected_len = 32 name = 'HSM password' if hsm.version.have_key_store_decrypt(): expected_len = 64 name = 'master key' if args.stdin: password = sys.stdin.readline() while p...
[ "def", "get_password", "(", "hsm", ",", "args", ")", ":", "expected_len", "=", "32", "name", "=", "'HSM password'", "if", "hsm", ".", "version", ".", "have_key_store_decrypt", "(", ")", ":", "expected_len", "=", "64", "name", "=", "'master key'", "if", "ar...
Get password of correct length for this YubiHSM version.
[ "Get", "password", "of", "correct", "length", "for", "this", "YubiHSM", "version", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/tools/keystore_unlock.py#L56-L82
8,963
Yubico/python-pyhsm
pyhsm/tools/keystore_unlock.py
get_otp
def get_otp(hsm, args): """ Get OTP from YubiKey. """ if args.no_otp: return None if hsm.version.have_unlock(): if args.stdin: otp = sys.stdin.readline() while otp and otp[-1] == '\n': otp = otp[:-1] else: otp = raw_input('Enter adm...
python
def get_otp(hsm, args): """ Get OTP from YubiKey. """ if args.no_otp: return None if hsm.version.have_unlock(): if args.stdin: otp = sys.stdin.readline() while otp and otp[-1] == '\n': otp = otp[:-1] else: otp = raw_input('Enter adm...
[ "def", "get_otp", "(", "hsm", ",", "args", ")", ":", "if", "args", ".", "no_otp", ":", "return", "None", "if", "hsm", ".", "version", ".", "have_unlock", "(", ")", ":", "if", "args", ".", "stdin", ":", "otp", "=", "sys", ".", "stdin", ".", "readl...
Get OTP from YubiKey.
[ "Get", "OTP", "from", "YubiKey", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/tools/keystore_unlock.py#L84-L100
8,964
ResidentMario/geoplot
geoplot/crs.py
Base.load
def load(self, df, centerings): """ A moderately mind-bendy meta-method which abstracts the internals of individual projections' load procedures. Parameters ---------- proj : geoplot.crs object instance A disguised reference to ``self``. df : GeoDataFrame ...
python
def load(self, df, centerings): """ A moderately mind-bendy meta-method which abstracts the internals of individual projections' load procedures. Parameters ---------- proj : geoplot.crs object instance A disguised reference to ``self``. df : GeoDataFrame ...
[ "def", "load", "(", "self", ",", "df", ",", "centerings", ")", ":", "centering_variables", "=", "dict", "(", ")", "if", "not", "df", ".", "empty", "and", "df", ".", "geometry", ".", "notna", "(", ")", ".", "any", "(", ")", ":", "for", "key", ",",...
A moderately mind-bendy meta-method which abstracts the internals of individual projections' load procedures. Parameters ---------- proj : geoplot.crs object instance A disguised reference to ``self``. df : GeoDataFrame The GeoDataFrame which has been passed as i...
[ "A", "moderately", "mind", "-", "bendy", "meta", "-", "method", "which", "abstracts", "the", "internals", "of", "individual", "projections", "load", "procedures", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/crs.py#L26-L62
8,965
ResidentMario/geoplot
geoplot/crs.py
Filtering.load
def load(self, df, centerings): """Call `load` method with `centerings` filtered to keys in `self.filter_`.""" return super().load( df, {key: value for key, value in centerings.items() if key in self.filter_} )
python
def load(self, df, centerings): """Call `load` method with `centerings` filtered to keys in `self.filter_`.""" return super().load( df, {key: value for key, value in centerings.items() if key in self.filter_} )
[ "def", "load", "(", "self", ",", "df", ",", "centerings", ")", ":", "return", "super", "(", ")", ".", "load", "(", "df", ",", "{", "key", ":", "value", "for", "key", ",", "value", "in", "centerings", ".", "items", "(", ")", "if", "key", "in", "...
Call `load` method with `centerings` filtered to keys in `self.filter_`.
[ "Call", "load", "method", "with", "centerings", "filtered", "to", "keys", "in", "self", ".", "filter_", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/crs.py#L99-L106
8,966
ResidentMario/geoplot
geoplot/utils.py
gaussian_points
def gaussian_points(loc=(0, 0), scale=(10, 10), n=100): """ Generates and returns `n` normally distributed points centered at `loc` with `scale` x and y directionality. """ arr = np.random.normal(loc, scale, (n, 2)) return gpd.GeoSeries([shapely.geometry.Point(x, y) for (x, y) in arr])
python
def gaussian_points(loc=(0, 0), scale=(10, 10), n=100): """ Generates and returns `n` normally distributed points centered at `loc` with `scale` x and y directionality. """ arr = np.random.normal(loc, scale, (n, 2)) return gpd.GeoSeries([shapely.geometry.Point(x, y) for (x, y) in arr])
[ "def", "gaussian_points", "(", "loc", "=", "(", "0", ",", "0", ")", ",", "scale", "=", "(", "10", ",", "10", ")", ",", "n", "=", "100", ")", ":", "arr", "=", "np", ".", "random", ".", "normal", "(", "loc", ",", "scale", ",", "(", "n", ",", ...
Generates and returns `n` normally distributed points centered at `loc` with `scale` x and y directionality.
[ "Generates", "and", "returns", "n", "normally", "distributed", "points", "centered", "at", "loc", "with", "scale", "x", "and", "y", "directionality", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/utils.py#L14-L20
8,967
ResidentMario/geoplot
geoplot/utils.py
classify_clusters
def classify_clusters(points, n=10): """ Return an array of K-Means cluster classes for an array of `shapely.geometry.Point` objects. """ arr = [[p.x, p.y] for p in points.values] clf = KMeans(n_clusters=n) clf.fit(arr) classes = clf.predict(arr) return classes
python
def classify_clusters(points, n=10): """ Return an array of K-Means cluster classes for an array of `shapely.geometry.Point` objects. """ arr = [[p.x, p.y] for p in points.values] clf = KMeans(n_clusters=n) clf.fit(arr) classes = clf.predict(arr) return classes
[ "def", "classify_clusters", "(", "points", ",", "n", "=", "10", ")", ":", "arr", "=", "[", "[", "p", ".", "x", ",", "p", ".", "y", "]", "for", "p", "in", "points", ".", "values", "]", "clf", "=", "KMeans", "(", "n_clusters", "=", "n", ")", "c...
Return an array of K-Means cluster classes for an array of `shapely.geometry.Point` objects.
[ "Return", "an", "array", "of", "K", "-", "Means", "cluster", "classes", "for", "an", "array", "of", "shapely", ".", "geometry", ".", "Point", "objects", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/utils.py#L23-L31
8,968
ResidentMario/geoplot
geoplot/utils.py
gaussian_polygons
def gaussian_polygons(points, n=10): """ Returns an array of approximately `n` `shapely.geometry.Polygon` objects for an array of `shapely.geometry.Point` objects. """ gdf = gpd.GeoDataFrame(data={'cluster_number': classify_clusters(points, n=n)}, geometry=points) polygons = [] for i in rang...
python
def gaussian_polygons(points, n=10): """ Returns an array of approximately `n` `shapely.geometry.Polygon` objects for an array of `shapely.geometry.Point` objects. """ gdf = gpd.GeoDataFrame(data={'cluster_number': classify_clusters(points, n=n)}, geometry=points) polygons = [] for i in rang...
[ "def", "gaussian_polygons", "(", "points", ",", "n", "=", "10", ")", ":", "gdf", "=", "gpd", ".", "GeoDataFrame", "(", "data", "=", "{", "'cluster_number'", ":", "classify_clusters", "(", "points", ",", "n", "=", "n", ")", "}", ",", "geometry", "=", ...
Returns an array of approximately `n` `shapely.geometry.Polygon` objects for an array of `shapely.geometry.Point` objects.
[ "Returns", "an", "array", "of", "approximately", "n", "shapely", ".", "geometry", ".", "Polygon", "objects", "for", "an", "array", "of", "shapely", ".", "geometry", ".", "Point", "objects", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/utils.py#L34-L46
8,969
ResidentMario/geoplot
geoplot/utils.py
gaussian_multi_polygons
def gaussian_multi_polygons(points, n=10): """ Returns an array of approximately `n` `shapely.geometry.MultiPolygon` objects for an array of `shapely.geometry.Point` objects. """ polygons = gaussian_polygons(points, n*2) # Randomly stitch them together. polygon_pairs = [shapely.geometry.Mult...
python
def gaussian_multi_polygons(points, n=10): """ Returns an array of approximately `n` `shapely.geometry.MultiPolygon` objects for an array of `shapely.geometry.Point` objects. """ polygons = gaussian_polygons(points, n*2) # Randomly stitch them together. polygon_pairs = [shapely.geometry.Mult...
[ "def", "gaussian_multi_polygons", "(", "points", ",", "n", "=", "10", ")", ":", "polygons", "=", "gaussian_polygons", "(", "points", ",", "n", "*", "2", ")", "# Randomly stitch them together.", "polygon_pairs", "=", "[", "shapely", ".", "geometry", ".", "Multi...
Returns an array of approximately `n` `shapely.geometry.MultiPolygon` objects for an array of `shapely.geometry.Point` objects.
[ "Returns", "an", "array", "of", "approximately", "n", "shapely", ".", "geometry", ".", "MultiPolygon", "objects", "for", "an", "array", "of", "shapely", ".", "geometry", ".", "Point", "objects", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/utils.py#L49-L57
8,970
ResidentMario/geoplot
geoplot/utils.py
uniform_random_global_points
def uniform_random_global_points(n=100): """ Returns an array of `n` uniformally distributed `shapely.geometry.Point` objects. Points are coordinates distributed equivalently across the Earth's surface. """ xs = np.random.uniform(-180, 180, n) ys = np.random.uniform(-90, 90, n) return [shape...
python
def uniform_random_global_points(n=100): """ Returns an array of `n` uniformally distributed `shapely.geometry.Point` objects. Points are coordinates distributed equivalently across the Earth's surface. """ xs = np.random.uniform(-180, 180, n) ys = np.random.uniform(-90, 90, n) return [shape...
[ "def", "uniform_random_global_points", "(", "n", "=", "100", ")", ":", "xs", "=", "np", ".", "random", ".", "uniform", "(", "-", "180", ",", "180", ",", "n", ")", "ys", "=", "np", ".", "random", ".", "uniform", "(", "-", "90", ",", "90", ",", "...
Returns an array of `n` uniformally distributed `shapely.geometry.Point` objects. Points are coordinates distributed equivalently across the Earth's surface.
[ "Returns", "an", "array", "of", "n", "uniformally", "distributed", "shapely", ".", "geometry", ".", "Point", "objects", ".", "Points", "are", "coordinates", "distributed", "equivalently", "across", "the", "Earth", "s", "surface", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/utils.py#L60-L67
8,971
ResidentMario/geoplot
geoplot/utils.py
uniform_random_global_network
def uniform_random_global_network(loc=2000, scale=250, n=100): """ Returns an array of `n` uniformally randomly distributed `shapely.geometry.Point` objects. """ arr = (np.random.normal(loc, scale, n)).astype(int) return pd.DataFrame(data={'mock_variable': arr, 'from': ...
python
def uniform_random_global_network(loc=2000, scale=250, n=100): """ Returns an array of `n` uniformally randomly distributed `shapely.geometry.Point` objects. """ arr = (np.random.normal(loc, scale, n)).astype(int) return pd.DataFrame(data={'mock_variable': arr, 'from': ...
[ "def", "uniform_random_global_network", "(", "loc", "=", "2000", ",", "scale", "=", "250", ",", "n", "=", "100", ")", ":", "arr", "=", "(", "np", ".", "random", ".", "normal", "(", "loc", ",", "scale", ",", "n", ")", ")", ".", "astype", "(", "int...
Returns an array of `n` uniformally randomly distributed `shapely.geometry.Point` objects.
[ "Returns", "an", "array", "of", "n", "uniformally", "randomly", "distributed", "shapely", ".", "geometry", ".", "Point", "objects", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/utils.py#L70-L77
8,972
ResidentMario/geoplot
geoplot/quad.py
subpartition
def subpartition(quadtree, nmin, nmax): """ Recursive core of the ``QuadTree.partition`` method. Just five lines of code, amazingly. Parameters ---------- quadtree : QuadTree object instance The QuadTree object instance being partitioned. nmin : int The splitting threshold. If t...
python
def subpartition(quadtree, nmin, nmax): """ Recursive core of the ``QuadTree.partition`` method. Just five lines of code, amazingly. Parameters ---------- quadtree : QuadTree object instance The QuadTree object instance being partitioned. nmin : int The splitting threshold. If t...
[ "def", "subpartition", "(", "quadtree", ",", "nmin", ",", "nmax", ")", ":", "subtrees", "=", "quadtree", ".", "split", "(", ")", "if", "quadtree", ".", "n", ">", "nmax", ":", "return", "[", "q", ".", "partition", "(", "nmin", ",", "nmax", ")", "for...
Recursive core of the ``QuadTree.partition`` method. Just five lines of code, amazingly. Parameters ---------- quadtree : QuadTree object instance The QuadTree object instance being partitioned. nmin : int The splitting threshold. If this is not met this method will return a listing con...
[ "Recursive", "core", "of", "the", "QuadTree", ".", "partition", "method", ".", "Just", "five", "lines", "of", "code", "amazingly", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/quad.py#L116-L138
8,973
ResidentMario/geoplot
geoplot/quad.py
QuadTree.split
def split(self): """ Splits the current QuadTree instance four ways through the midpoint. Returns ------- A list of four "sub" QuadTree instances, corresponding with the first, second, third, and fourth quartiles, respectively. """ # TODO: Investigate why...
python
def split(self): """ Splits the current QuadTree instance four ways through the midpoint. Returns ------- A list of four "sub" QuadTree instances, corresponding with the first, second, third, and fourth quartiles, respectively. """ # TODO: Investigate why...
[ "def", "split", "(", "self", ")", ":", "# TODO: Investigate why a small number of entries are lost every time this method is run.", "min_x", ",", "max_x", ",", "min_y", ",", "max_y", "=", "self", ".", "bounds", "mid_x", ",", "mid_y", "=", "(", "min_x", "+", "max_x",...
Splits the current QuadTree instance four ways through the midpoint. Returns ------- A list of four "sub" QuadTree instances, corresponding with the first, second, third, and fourth quartiles, respectively.
[ "Splits", "the", "current", "QuadTree", "instance", "four", "ways", "through", "the", "midpoint", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/quad.py#L71-L88
8,974
ResidentMario/geoplot
geoplot/quad.py
QuadTree.partition
def partition(self, nmin, nmax): """ This method call decomposes a QuadTree instances into a list of sub- QuadTree instances which are the smallest possible geospatial "buckets", given the current splitting rules, containing at least ``thresh`` points. Parameters -------...
python
def partition(self, nmin, nmax): """ This method call decomposes a QuadTree instances into a list of sub- QuadTree instances which are the smallest possible geospatial "buckets", given the current splitting rules, containing at least ``thresh`` points. Parameters -------...
[ "def", "partition", "(", "self", ",", "nmin", ",", "nmax", ")", ":", "if", "self", ".", "n", "<", "nmin", ":", "return", "[", "self", "]", "else", ":", "ret", "=", "subpartition", "(", "self", ",", "nmin", ",", "nmax", ")", "return", "flatten", "...
This method call decomposes a QuadTree instances into a list of sub- QuadTree instances which are the smallest possible geospatial "buckets", given the current splitting rules, containing at least ``thresh`` points. Parameters ---------- thresh : int The minimum numb...
[ "This", "method", "call", "decomposes", "a", "QuadTree", "instances", "into", "a", "list", "of", "sub", "-", "QuadTree", "instances", "which", "are", "the", "smallest", "possible", "geospatial", "buckets", "given", "the", "current", "splitting", "rules", "contai...
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/quad.py#L90-L113
8,975
ResidentMario/geoplot
docs/examples/nyc-parking-tickets.py
plot_state_to_ax
def plot_state_to_ax(state, ax): """Reusable plotting wrapper.""" gplt.choropleth(tickets.set_index('id').loc[:, [state, 'geometry']], hue=state, projection=gcrs.AlbersEqualArea(), cmap='Blues', linewidth=0.0, ax=ax) gplt.polyplot(boroughs, project...
python
def plot_state_to_ax(state, ax): """Reusable plotting wrapper.""" gplt.choropleth(tickets.set_index('id').loc[:, [state, 'geometry']], hue=state, projection=gcrs.AlbersEqualArea(), cmap='Blues', linewidth=0.0, ax=ax) gplt.polyplot(boroughs, project...
[ "def", "plot_state_to_ax", "(", "state", ",", "ax", ")", ":", "gplt", ".", "choropleth", "(", "tickets", ".", "set_index", "(", "'id'", ")", ".", "loc", "[", ":", ",", "[", "state", ",", "'geometry'", "]", "]", ",", "hue", "=", "state", ",", "proje...
Reusable plotting wrapper.
[ "Reusable", "plotting", "wrapper", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/docs/examples/nyc-parking-tickets.py#L19-L25
8,976
ResidentMario/geoplot
geoplot/geoplot.py
polyplot
def polyplot(df, projection=None, extent=None, figsize=(8, 6), ax=None, edgecolor='black', facecolor='None', **kwargs): """ Trivial polygonal plot. Parameters ---------- df : GeoDataFrame The data being plotted. projection : geoplot.cr...
python
def polyplot(df, projection=None, extent=None, figsize=(8, 6), ax=None, edgecolor='black', facecolor='None', **kwargs): """ Trivial polygonal plot. Parameters ---------- df : GeoDataFrame The data being plotted. projection : geoplot.cr...
[ "def", "polyplot", "(", "df", ",", "projection", "=", "None", ",", "extent", "=", "None", ",", "figsize", "=", "(", "8", ",", "6", ")", ",", "ax", "=", "None", ",", "edgecolor", "=", "'black'", ",", "facecolor", "=", "'None'", ",", "*", "*", "kwa...
Trivial polygonal plot. Parameters ---------- df : GeoDataFrame The data being plotted. projection : geoplot.crs object instance, optional A geographic projection. For more information refer to `the tutorial page on projections <https://nbviewer.jupyter.org/github/ResidentMario/...
[ "Trivial", "polygonal", "plot", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/geoplot.py#L346-L462
8,977
ResidentMario/geoplot
geoplot/geoplot.py
choropleth
def choropleth(df, projection=None, hue=None, scheme=None, k=5, cmap='Set1', categorical=False, vmin=None, vmax=None, legend=False, legend_kwargs=None, legend_labels=None, extent=None, figsize=(8, 6), ax=None, **kwargs): """ ...
python
def choropleth(df, projection=None, hue=None, scheme=None, k=5, cmap='Set1', categorical=False, vmin=None, vmax=None, legend=False, legend_kwargs=None, legend_labels=None, extent=None, figsize=(8, 6), ax=None, **kwargs): """ ...
[ "def", "choropleth", "(", "df", ",", "projection", "=", "None", ",", "hue", "=", "None", ",", "scheme", "=", "None", ",", "k", "=", "5", ",", "cmap", "=", "'Set1'", ",", "categorical", "=", "False", ",", "vmin", "=", "None", ",", "vmax", "=", "No...
Area aggregation plot. Parameters ---------- df : GeoDataFrame The data being plotted. projection : geoplot.crs object instance, optional A geographic projection. For more information refer to `the tutorial page on projections <https://nbviewer.jupyter.org/github/ResidentMario/g...
[ "Area", "aggregation", "plot", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/geoplot.py#L465-L687
8,978
ResidentMario/geoplot
geoplot/geoplot.py
_get_envelopes_min_maxes
def _get_envelopes_min_maxes(envelopes): """ Returns the extrema of the inputted polygonal envelopes. Used for setting chart extent where appropriate. Note tha the ``Quadtree.bounds`` object property serves a similar role. Parameters ---------- envelopes : GeoSeries The envelopes of the...
python
def _get_envelopes_min_maxes(envelopes): """ Returns the extrema of the inputted polygonal envelopes. Used for setting chart extent where appropriate. Note tha the ``Quadtree.bounds`` object property serves a similar role. Parameters ---------- envelopes : GeoSeries The envelopes of the...
[ "def", "_get_envelopes_min_maxes", "(", "envelopes", ")", ":", "xmin", "=", "np", ".", "min", "(", "envelopes", ".", "map", "(", "lambda", "linearring", ":", "np", ".", "min", "(", "[", "linearring", ".", "coords", "[", "1", "]", "[", "0", "]", ",", ...
Returns the extrema of the inputted polygonal envelopes. Used for setting chart extent where appropriate. Note tha the ``Quadtree.bounds`` object property serves a similar role. Parameters ---------- envelopes : GeoSeries The envelopes of the given geometries, as would be returned by e.g. ``dat...
[ "Returns", "the", "extrema", "of", "the", "inputted", "polygonal", "envelopes", ".", "Used", "for", "setting", "chart", "extent", "where", "appropriate", ".", "Note", "tha", "the", "Quadtree", ".", "bounds", "object", "property", "serves", "a", "similar", "rol...
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/geoplot.py#L2192-L2224
8,979
ResidentMario/geoplot
geoplot/geoplot.py
_get_envelopes_centroid
def _get_envelopes_centroid(envelopes): """ Returns the centroid of an inputted geometry column. Not currently in use, as this is now handled by this library's CRS wrapper directly. Light wrapper over ``_get_envelopes_min_maxes``. Parameters ---------- envelopes : GeoSeries The envelope...
python
def _get_envelopes_centroid(envelopes): """ Returns the centroid of an inputted geometry column. Not currently in use, as this is now handled by this library's CRS wrapper directly. Light wrapper over ``_get_envelopes_min_maxes``. Parameters ---------- envelopes : GeoSeries The envelope...
[ "def", "_get_envelopes_centroid", "(", "envelopes", ")", ":", "xmin", ",", "xmax", ",", "ymin", ",", "ymax", "=", "_get_envelopes_min_maxes", "(", "envelopes", ")", "return", "np", ".", "mean", "(", "xmin", ",", "xmax", ")", ",", "np", ".", "mean", "(", ...
Returns the centroid of an inputted geometry column. Not currently in use, as this is now handled by this library's CRS wrapper directly. Light wrapper over ``_get_envelopes_min_maxes``. Parameters ---------- envelopes : GeoSeries The envelopes of the given geometries, as would be returned by e...
[ "Returns", "the", "centroid", "of", "an", "inputted", "geometry", "column", ".", "Not", "currently", "in", "use", "as", "this", "is", "now", "handled", "by", "this", "library", "s", "CRS", "wrapper", "directly", ".", "Light", "wrapper", "over", "_get_envelop...
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/geoplot.py#L2227-L2243
8,980
ResidentMario/geoplot
geoplot/geoplot.py
_set_extent
def _set_extent(ax, projection, extent, extrema): """ Sets the plot extent. Parameters ---------- ax : cartopy.GeoAxesSubplot instance The axis whose boundaries are being tweaked. projection : None or geoplot.crs instance The projection, if one is being used. extent : None o...
python
def _set_extent(ax, projection, extent, extrema): """ Sets the plot extent. Parameters ---------- ax : cartopy.GeoAxesSubplot instance The axis whose boundaries are being tweaked. projection : None or geoplot.crs instance The projection, if one is being used. extent : None o...
[ "def", "_set_extent", "(", "ax", ",", "projection", ",", "extent", ",", "extrema", ")", ":", "if", "extent", ":", "xmin", ",", "xmax", ",", "ymin", ",", "ymax", "=", "extent", "xmin", ",", "xmax", ",", "ymin", ",", "ymax", "=", "max", "(", "xmin", ...
Sets the plot extent. Parameters ---------- ax : cartopy.GeoAxesSubplot instance The axis whose boundaries are being tweaked. projection : None or geoplot.crs instance The projection, if one is being used. extent : None or (xmin, xmax, ymin, ymax) tuple A copy of the ``exten...
[ "Sets", "the", "plot", "extent", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/geoplot.py#L2246-L2285
8,981
ResidentMario/geoplot
geoplot/geoplot.py
_lay_out_axes
def _lay_out_axes(ax, projection): """ ``cartopy`` enables a a transparent background patch and an "outline" patch by default. This short method simply hides these extraneous visual features. If the plot is a pure ``matplotlib`` one, it does the same thing by removing the axis altogether. Parameter...
python
def _lay_out_axes(ax, projection): """ ``cartopy`` enables a a transparent background patch and an "outline" patch by default. This short method simply hides these extraneous visual features. If the plot is a pure ``matplotlib`` one, it does the same thing by removing the axis altogether. Parameter...
[ "def", "_lay_out_axes", "(", "ax", ",", "projection", ")", ":", "if", "projection", "is", "not", "None", ":", "try", ":", "ax", ".", "background_patch", ".", "set_visible", "(", "False", ")", "ax", ".", "outline_patch", ".", "set_visible", "(", "False", ...
``cartopy`` enables a a transparent background patch and an "outline" patch by default. This short method simply hides these extraneous visual features. If the plot is a pure ``matplotlib`` one, it does the same thing by removing the axis altogether. Parameters ---------- ax : matplotlib.Axes insta...
[ "cartopy", "enables", "a", "a", "transparent", "background", "patch", "and", "an", "outline", "patch", "by", "default", ".", "This", "short", "method", "simply", "hides", "these", "extraneous", "visual", "features", ".", "If", "the", "plot", "is", "a", "pure...
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/geoplot.py#L2288-L2312
8,982
ResidentMario/geoplot
geoplot/geoplot.py
_continuous_colormap
def _continuous_colormap(hue, cmap, vmin, vmax): """ Creates a continuous colormap. Parameters ---------- hue : iterable The data column whose entries are being discretely colorized. Note that although top-level plotter ``hue`` parameters ingest many argument signatures, not just it...
python
def _continuous_colormap(hue, cmap, vmin, vmax): """ Creates a continuous colormap. Parameters ---------- hue : iterable The data column whose entries are being discretely colorized. Note that although top-level plotter ``hue`` parameters ingest many argument signatures, not just it...
[ "def", "_continuous_colormap", "(", "hue", ",", "cmap", ",", "vmin", ",", "vmax", ")", ":", "mn", "=", "min", "(", "hue", ")", "if", "vmin", "is", "None", "else", "vmin", "mx", "=", "max", "(", "hue", ")", "if", "vmax", "is", "None", "else", "vma...
Creates a continuous colormap. Parameters ---------- hue : iterable The data column whose entries are being discretely colorized. Note that although top-level plotter ``hue`` parameters ingest many argument signatures, not just iterables, they are all preprocessed to standardized it...
[ "Creates", "a", "continuous", "colormap", "." ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/geoplot.py#L2345-L2374
8,983
ResidentMario/geoplot
geoplot/geoplot.py
_discrete_colorize
def _discrete_colorize(categorical, hue, scheme, k, cmap, vmin, vmax): """ Creates a discrete colormap, either using an already-categorical data variable or by bucketing a non-categorical ordinal one. If a scheme is provided we compute a distribution for the given data. If one is not provided we assume ...
python
def _discrete_colorize(categorical, hue, scheme, k, cmap, vmin, vmax): """ Creates a discrete colormap, either using an already-categorical data variable or by bucketing a non-categorical ordinal one. If a scheme is provided we compute a distribution for the given data. If one is not provided we assume ...
[ "def", "_discrete_colorize", "(", "categorical", ",", "hue", ",", "scheme", ",", "k", ",", "cmap", ",", "vmin", ",", "vmax", ")", ":", "if", "not", "categorical", ":", "binning", "=", "_mapclassify_choro", "(", "hue", ",", "scheme", ",", "k", "=", "k",...
Creates a discrete colormap, either using an already-categorical data variable or by bucketing a non-categorical ordinal one. If a scheme is provided we compute a distribution for the given data. If one is not provided we assume that the input data is categorical. This code makes extensive use of ``geopand...
[ "Creates", "a", "discrete", "colormap", "either", "using", "an", "already", "-", "categorical", "data", "variable", "or", "by", "bucketing", "a", "non", "-", "categorical", "ordinal", "one", ".", "If", "a", "scheme", "is", "provided", "we", "compute", "a", ...
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/geoplot.py#L2377-L2428
8,984
ResidentMario/geoplot
geoplot/geoplot.py
_norm_cmap
def _norm_cmap(values, cmap, normalize, cm, vmin=None, vmax=None): """ Normalize and set colormap. Taken from geopandas@0.2.1 codebase, removed in geopandas@0.3.0. """ mn = min(values) if vmin is None else vmin mx = max(values) if vmax is None else vmax norm = normalize(vmin=mn, vmax=mx) n_...
python
def _norm_cmap(values, cmap, normalize, cm, vmin=None, vmax=None): """ Normalize and set colormap. Taken from geopandas@0.2.1 codebase, removed in geopandas@0.3.0. """ mn = min(values) if vmin is None else vmin mx = max(values) if vmax is None else vmax norm = normalize(vmin=mn, vmax=mx) n_...
[ "def", "_norm_cmap", "(", "values", ",", "cmap", ",", "normalize", ",", "cm", ",", "vmin", "=", "None", ",", "vmax", "=", "None", ")", ":", "mn", "=", "min", "(", "values", ")", "if", "vmin", "is", "None", "else", "vmin", "mx", "=", "max", "(", ...
Normalize and set colormap. Taken from geopandas@0.2.1 codebase, removed in geopandas@0.3.0.
[ "Normalize", "and", "set", "colormap", ".", "Taken", "from", "geopandas" ]
942b474878187a87a95a27fbe41285dfdc1d20ca
https://github.com/ResidentMario/geoplot/blob/942b474878187a87a95a27fbe41285dfdc1d20ca/geoplot/geoplot.py#L2733-L2742
8,985
tmux-python/libtmux
libtmux/common.py
get_version
def get_version(): """ Return tmux version. If tmux is built from git master, the version returned will be the latest version appended with -master, e.g. ``2.4-master``. If using OpenBSD's base system tmux, the version will have ``-openbsd`` appended to the latest version, e.g. ``2.4-openbsd``...
python
def get_version(): """ Return tmux version. If tmux is built from git master, the version returned will be the latest version appended with -master, e.g. ``2.4-master``. If using OpenBSD's base system tmux, the version will have ``-openbsd`` appended to the latest version, e.g. ``2.4-openbsd``...
[ "def", "get_version", "(", ")", ":", "proc", "=", "tmux_cmd", "(", "'-V'", ")", "if", "proc", ".", "stderr", ":", "if", "proc", ".", "stderr", "[", "0", "]", "==", "'tmux: unknown option -- V'", ":", "if", "sys", ".", "platform", ".", "startswith", "("...
Return tmux version. If tmux is built from git master, the version returned will be the latest version appended with -master, e.g. ``2.4-master``. If using OpenBSD's base system tmux, the version will have ``-openbsd`` appended to the latest version, e.g. ``2.4-openbsd``. Returns ------- ...
[ "Return", "tmux", "version", "." ]
8eb2f8bbea3a025c1567b1516653414dbc24e1fc
https://github.com/tmux-python/libtmux/blob/8eb2f8bbea3a025c1567b1516653414dbc24e1fc/libtmux/common.py#L442-L476
8,986
tmux-python/libtmux
libtmux/common.py
has_minimum_version
def has_minimum_version(raises=True): """ Return if tmux meets version requirement. Version >1.8 or above. Parameters ---------- raises : bool raise exception if below minimum version requirement Returns ------- bool True if tmux meets minimum required version. Rai...
python
def has_minimum_version(raises=True): """ Return if tmux meets version requirement. Version >1.8 or above. Parameters ---------- raises : bool raise exception if below minimum version requirement Returns ------- bool True if tmux meets minimum required version. Rai...
[ "def", "has_minimum_version", "(", "raises", "=", "True", ")", ":", "if", "get_version", "(", ")", "<", "LooseVersion", "(", "TMUX_MIN_VERSION", ")", ":", "if", "raises", ":", "raise", "exc", ".", "VersionTooLow", "(", "'libtmux only supports tmux %s and greater. ...
Return if tmux meets version requirement. Version >1.8 or above. Parameters ---------- raises : bool raise exception if below minimum version requirement Returns ------- bool True if tmux meets minimum required version. Raises ------ libtmux.exc.VersionTooLow ...
[ "Return", "if", "tmux", "meets", "version", "requirement", ".", "Version", ">", "1", ".", "8", "or", "above", "." ]
8eb2f8bbea3a025c1567b1516653414dbc24e1fc
https://github.com/tmux-python/libtmux/blob/8eb2f8bbea3a025c1567b1516653414dbc24e1fc/libtmux/common.py#L564-L603
8,987
tmux-python/libtmux
libtmux/common.py
session_check_name
def session_check_name(session_name): """ Raises exception session name invalid, modeled after tmux function. tmux(1) session names may not be empty, or include periods or colons. These delimiters are reserved for noting session, window and pane. Parameters ---------- session_name : str ...
python
def session_check_name(session_name): """ Raises exception session name invalid, modeled after tmux function. tmux(1) session names may not be empty, or include periods or colons. These delimiters are reserved for noting session, window and pane. Parameters ---------- session_name : str ...
[ "def", "session_check_name", "(", "session_name", ")", ":", "if", "not", "session_name", "or", "len", "(", "session_name", ")", "==", "0", ":", "raise", "exc", ".", "BadSessionName", "(", "\"tmux session names may not be empty.\"", ")", "elif", "'.'", "in", "ses...
Raises exception session name invalid, modeled after tmux function. tmux(1) session names may not be empty, or include periods or colons. These delimiters are reserved for noting session, window and pane. Parameters ---------- session_name : str Name of session. Raises ------ ...
[ "Raises", "exception", "session", "name", "invalid", "modeled", "after", "tmux", "function", "." ]
8eb2f8bbea3a025c1567b1516653414dbc24e1fc
https://github.com/tmux-python/libtmux/blob/8eb2f8bbea3a025c1567b1516653414dbc24e1fc/libtmux/common.py#L606-L632
8,988
tmux-python/libtmux
libtmux/common.py
handle_option_error
def handle_option_error(error): """Raises exception if error in option command found. Purpose: As of tmux 2.4, there are now 3 different types of option errors: - unknown option - invalid option - ambiguous option Before 2.4, unknown option was the user. All errors raised will have the b...
python
def handle_option_error(error): """Raises exception if error in option command found. Purpose: As of tmux 2.4, there are now 3 different types of option errors: - unknown option - invalid option - ambiguous option Before 2.4, unknown option was the user. All errors raised will have the b...
[ "def", "handle_option_error", "(", "error", ")", ":", "if", "'unknown option'", "in", "error", ":", "raise", "exc", ".", "UnknownOption", "(", "error", ")", "elif", "'invalid option'", "in", "error", ":", "raise", "exc", ".", "InvalidOption", "(", "error", "...
Raises exception if error in option command found. Purpose: As of tmux 2.4, there are now 3 different types of option errors: - unknown option - invalid option - ambiguous option Before 2.4, unknown option was the user. All errors raised will have the base error of :exc:`exc.OptionError`. So...
[ "Raises", "exception", "if", "error", "in", "option", "command", "found", "." ]
8eb2f8bbea3a025c1567b1516653414dbc24e1fc
https://github.com/tmux-python/libtmux/blob/8eb2f8bbea3a025c1567b1516653414dbc24e1fc/libtmux/common.py#L635-L666
8,989
tmux-python/libtmux
libtmux/common.py
TmuxRelationalObject.where
def where(self, attrs, first=False): """ Return objects matching child objects properties. Parameters ---------- attrs : dict tmux properties to match values of Returns ------- list """ # from https://github.com/serkanyersen/...
python
def where(self, attrs, first=False): """ Return objects matching child objects properties. Parameters ---------- attrs : dict tmux properties to match values of Returns ------- list """ # from https://github.com/serkanyersen/...
[ "def", "where", "(", "self", ",", "attrs", ",", "first", "=", "False", ")", ":", "# from https://github.com/serkanyersen/underscore.py", "def", "by", "(", "val", ",", "*", "args", ")", ":", "for", "key", ",", "value", "in", "attrs", ".", "items", "(", ")...
Return objects matching child objects properties. Parameters ---------- attrs : dict tmux properties to match values of Returns ------- list
[ "Return", "objects", "matching", "child", "objects", "properties", "." ]
8eb2f8bbea3a025c1567b1516653414dbc24e1fc
https://github.com/tmux-python/libtmux/blob/8eb2f8bbea3a025c1567b1516653414dbc24e1fc/libtmux/common.py#L324-L351
8,990
tmux-python/libtmux
libtmux/common.py
TmuxRelationalObject.get_by_id
def get_by_id(self, id): """ Return object based on ``child_id_attribute``. Parameters ---------- val : str Returns ------- object Notes ----- Based on `.get()`_ from `backbone.js`_. .. _backbone.js: http://backbonejs.or...
python
def get_by_id(self, id): """ Return object based on ``child_id_attribute``. Parameters ---------- val : str Returns ------- object Notes ----- Based on `.get()`_ from `backbone.js`_. .. _backbone.js: http://backbonejs.or...
[ "def", "get_by_id", "(", "self", ",", "id", ")", ":", "for", "child", "in", "self", ".", "children", ":", "if", "child", "[", "self", ".", "child_id_attribute", "]", "==", "id", ":", "return", "child", "else", ":", "continue", "return", "None" ]
Return object based on ``child_id_attribute``. Parameters ---------- val : str Returns ------- object Notes ----- Based on `.get()`_ from `backbone.js`_. .. _backbone.js: http://backbonejs.org/ .. _.get(): http://backbonejs.org/...
[ "Return", "object", "based", "on", "child_id_attribute", "." ]
8eb2f8bbea3a025c1567b1516653414dbc24e1fc
https://github.com/tmux-python/libtmux/blob/8eb2f8bbea3a025c1567b1516653414dbc24e1fc/libtmux/common.py#L353-L378
8,991
tmux-python/libtmux
libtmux/window.py
Window.select_window
def select_window(self): """ Select window. Return ``self``. To select a window object asynchrously. If a ``window`` object exists and is no longer longer the current window, ``w.select_window()`` will make ``w`` the current window. Returns ------- :clas...
python
def select_window(self): """ Select window. Return ``self``. To select a window object asynchrously. If a ``window`` object exists and is no longer longer the current window, ``w.select_window()`` will make ``w`` the current window. Returns ------- :clas...
[ "def", "select_window", "(", "self", ")", ":", "target", "=", "(", "'%s:%s'", "%", "(", "self", ".", "get", "(", "'session_id'", ")", ",", "self", ".", "index", ")", ",", ")", "return", "self", ".", "session", ".", "select_window", "(", "target", ")"...
Select window. Return ``self``. To select a window object asynchrously. If a ``window`` object exists and is no longer longer the current window, ``w.select_window()`` will make ``w`` the current window. Returns ------- :class:`Window`
[ "Select", "window", ".", "Return", "self", "." ]
8eb2f8bbea3a025c1567b1516653414dbc24e1fc
https://github.com/tmux-python/libtmux/blob/8eb2f8bbea3a025c1567b1516653414dbc24e1fc/libtmux/window.py#L341-L354
8,992
tmux-python/libtmux
libtmux/server.py
Server.cmd
def cmd(self, *args, **kwargs): """ Execute tmux command and return output. Returns ------- :class:`common.tmux_cmd` Notes ----- .. versionchanged:: 0.8 Renamed from ``.tmux`` to ``.cmd``. """ args = list(args) if se...
python
def cmd(self, *args, **kwargs): """ Execute tmux command and return output. Returns ------- :class:`common.tmux_cmd` Notes ----- .. versionchanged:: 0.8 Renamed from ``.tmux`` to ``.cmd``. """ args = list(args) if se...
[ "def", "cmd", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "args", "=", "list", "(", "args", ")", "if", "self", ".", "socket_name", ":", "args", ".", "insert", "(", "0", ",", "'-L{0}'", ".", "format", "(", "self", ".", "soc...
Execute tmux command and return output. Returns ------- :class:`common.tmux_cmd` Notes ----- .. versionchanged:: 0.8 Renamed from ``.tmux`` to ``.cmd``.
[ "Execute", "tmux", "command", "and", "return", "output", "." ]
8eb2f8bbea3a025c1567b1516653414dbc24e1fc
https://github.com/tmux-python/libtmux/blob/8eb2f8bbea3a025c1567b1516653414dbc24e1fc/libtmux/server.py#L99-L129
8,993
tmux-python/libtmux
libtmux/session.py
Session.switch_client
def switch_client(self): """ Switch client to this session. Raises ------ :exc:`exc.LibTmuxException` """ proc = self.cmd('switch-client', '-t%s' % self.id) if proc.stderr: raise exc.LibTmuxException(proc.stderr)
python
def switch_client(self): """ Switch client to this session. Raises ------ :exc:`exc.LibTmuxException` """ proc = self.cmd('switch-client', '-t%s' % self.id) if proc.stderr: raise exc.LibTmuxException(proc.stderr)
[ "def", "switch_client", "(", "self", ")", ":", "proc", "=", "self", ".", "cmd", "(", "'switch-client'", ",", "'-t%s'", "%", "self", ".", "id", ")", "if", "proc", ".", "stderr", ":", "raise", "exc", ".", "LibTmuxException", "(", "proc", ".", "stderr", ...
Switch client to this session. Raises ------ :exc:`exc.LibTmuxException`
[ "Switch", "client", "to", "this", "session", "." ]
8eb2f8bbea3a025c1567b1516653414dbc24e1fc
https://github.com/tmux-python/libtmux/blob/8eb2f8bbea3a025c1567b1516653414dbc24e1fc/libtmux/session.py#L122-L134
8,994
Yubico/yubikey-manager
ykman/cli/opgp.py
openpgp
def openpgp(ctx): """ Manage OpenPGP Application. Examples: \b Set the retries for PIN, Reset Code and Admin PIN to 10: $ ykman openpgp set-retries 10 10 10 \b Require touch to use the authentication key: $ ykman openpgp touch aut on """ try: ctx.obj['contr...
python
def openpgp(ctx): """ Manage OpenPGP Application. Examples: \b Set the retries for PIN, Reset Code and Admin PIN to 10: $ ykman openpgp set-retries 10 10 10 \b Require touch to use the authentication key: $ ykman openpgp touch aut on """ try: ctx.obj['contr...
[ "def", "openpgp", "(", "ctx", ")", ":", "try", ":", "ctx", ".", "obj", "[", "'controller'", "]", "=", "OpgpController", "(", "ctx", ".", "obj", "[", "'dev'", "]", ".", "driver", ")", "except", "APDUError", "as", "e", ":", "if", "e", ".", "sw", "=...
Manage OpenPGP Application. Examples: \b Set the retries for PIN, Reset Code and Admin PIN to 10: $ ykman openpgp set-retries 10 10 10 \b Require touch to use the authentication key: $ ykman openpgp touch aut on
[ "Manage", "OpenPGP", "Application", "." ]
3ac27bc59ae76a59db9d09a530494add2edbbabf
https://github.com/Yubico/yubikey-manager/blob/3ac27bc59ae76a59db9d09a530494add2edbbabf/ykman/cli/opgp.py#L83-L104
8,995
Yubico/yubikey-manager
ykman/cli/opgp.py
info
def info(ctx): """ Display status of OpenPGP application. """ controller = ctx.obj['controller'] click.echo('OpenPGP version: %d.%d.%d' % controller.version) retries = controller.get_remaining_pin_tries() click.echo('PIN tries remaining: {}'.format(retries.pin)) click.echo('Reset code tr...
python
def info(ctx): """ Display status of OpenPGP application. """ controller = ctx.obj['controller'] click.echo('OpenPGP version: %d.%d.%d' % controller.version) retries = controller.get_remaining_pin_tries() click.echo('PIN tries remaining: {}'.format(retries.pin)) click.echo('Reset code tr...
[ "def", "info", "(", "ctx", ")", ":", "controller", "=", "ctx", ".", "obj", "[", "'controller'", "]", "click", ".", "echo", "(", "'OpenPGP version: %d.%d.%d'", "%", "controller", ".", "version", ")", "retries", "=", "controller", ".", "get_remaining_pin_tries",...
Display status of OpenPGP application.
[ "Display", "status", "of", "OpenPGP", "application", "." ]
3ac27bc59ae76a59db9d09a530494add2edbbabf
https://github.com/Yubico/yubikey-manager/blob/3ac27bc59ae76a59db9d09a530494add2edbbabf/ykman/cli/opgp.py#L109-L129
8,996
Yubico/yubikey-manager
ykman/cli/opgp.py
reset
def reset(ctx): """ Reset OpenPGP application. This action will wipe all OpenPGP data, and set all PINs to their default values. """ click.echo("Resetting OpenPGP data, don't remove your YubiKey...") ctx.obj['controller'].reset() click.echo('Success! All data has been cleared and defaul...
python
def reset(ctx): """ Reset OpenPGP application. This action will wipe all OpenPGP data, and set all PINs to their default values. """ click.echo("Resetting OpenPGP data, don't remove your YubiKey...") ctx.obj['controller'].reset() click.echo('Success! All data has been cleared and defaul...
[ "def", "reset", "(", "ctx", ")", ":", "click", ".", "echo", "(", "\"Resetting OpenPGP data, don't remove your YubiKey...\"", ")", "ctx", ".", "obj", "[", "'controller'", "]", ".", "reset", "(", ")", "click", ".", "echo", "(", "'Success! All data has been cleared a...
Reset OpenPGP application. This action will wipe all OpenPGP data, and set all PINs to their default values.
[ "Reset", "OpenPGP", "application", "." ]
3ac27bc59ae76a59db9d09a530494add2edbbabf
https://github.com/Yubico/yubikey-manager/blob/3ac27bc59ae76a59db9d09a530494add2edbbabf/ykman/cli/opgp.py#L137-L147
8,997
Yubico/yubikey-manager
ykman/cli/opgp.py
touch
def touch(ctx, key, policy, admin_pin, force): """ Manage touch policy for OpenPGP keys. \b KEY Key slot to set (sig, enc or aut). POLICY Touch policy to set (on, off or fixed). """ controller = ctx.obj['controller'] old_policy = controller.get_touch(key) if old_policy == TOUC...
python
def touch(ctx, key, policy, admin_pin, force): """ Manage touch policy for OpenPGP keys. \b KEY Key slot to set (sig, enc or aut). POLICY Touch policy to set (on, off or fixed). """ controller = ctx.obj['controller'] old_policy = controller.get_touch(key) if old_policy == TOUC...
[ "def", "touch", "(", "ctx", ",", "key", ",", "policy", ",", "admin_pin", ",", "force", ")", ":", "controller", "=", "ctx", ".", "obj", "[", "'controller'", "]", "old_policy", "=", "controller", ".", "get_touch", "(", "key", ")", "if", "old_policy", "==...
Manage touch policy for OpenPGP keys. \b KEY Key slot to set (sig, enc or aut). POLICY Touch policy to set (on, off or fixed).
[ "Manage", "touch", "policy", "for", "OpenPGP", "keys", "." ]
3ac27bc59ae76a59db9d09a530494add2edbbabf
https://github.com/Yubico/yubikey-manager/blob/3ac27bc59ae76a59db9d09a530494add2edbbabf/ykman/cli/opgp.py#L165-L183
8,998
Yubico/yubikey-manager
ykman/cli/opgp.py
set_pin_retries
def set_pin_retries(ctx, pw_attempts, admin_pin, force): """ Manage pin-retries. Sets the number of attempts available before locking for each PIN. PW_ATTEMPTS should be three integer values corresponding to the number of attempts for the PIN, Reset Code, and Admin PIN, respectively. """ c...
python
def set_pin_retries(ctx, pw_attempts, admin_pin, force): """ Manage pin-retries. Sets the number of attempts available before locking for each PIN. PW_ATTEMPTS should be three integer values corresponding to the number of attempts for the PIN, Reset Code, and Admin PIN, respectively. """ c...
[ "def", "set_pin_retries", "(", "ctx", ",", "pw_attempts", ",", "admin_pin", ",", "force", ")", ":", "controller", "=", "ctx", ".", "obj", "[", "'controller'", "]", "resets_pins", "=", "controller", ".", "version", "<", "(", "4", ",", "0", ",", "0", ")"...
Manage pin-retries. Sets the number of attempts available before locking for each PIN. PW_ATTEMPTS should be three integer values corresponding to the number of attempts for the PIN, Reset Code, and Admin PIN, respectively.
[ "Manage", "pin", "-", "retries", "." ]
3ac27bc59ae76a59db9d09a530494add2edbbabf
https://github.com/Yubico/yubikey-manager/blob/3ac27bc59ae76a59db9d09a530494add2edbbabf/ykman/cli/opgp.py#L192-L212
8,999
Yubico/yubikey-manager
ykman/cli/piv.py
piv
def piv(ctx): """ Manage PIV Application. Examples: \b Generate an ECC P-256 private key and a self-signed certificate in slot 9a: $ ykman piv generate-key --algorithm ECCP256 9a pubkey.pem $ ykman piv generate-certificate --subject "yubico" 9a pubkey.pem \b Change t...
python
def piv(ctx): """ Manage PIV Application. Examples: \b Generate an ECC P-256 private key and a self-signed certificate in slot 9a: $ ykman piv generate-key --algorithm ECCP256 9a pubkey.pem $ ykman piv generate-certificate --subject "yubico" 9a pubkey.pem \b Change t...
[ "def", "piv", "(", "ctx", ")", ":", "try", ":", "ctx", ".", "obj", "[", "'controller'", "]", "=", "PivController", "(", "ctx", ".", "obj", "[", "'dev'", "]", ".", "driver", ")", "except", "APDUError", "as", "e", ":", "if", "e", ".", "sw", "==", ...
Manage PIV Application. Examples: \b Generate an ECC P-256 private key and a self-signed certificate in slot 9a: $ ykman piv generate-key --algorithm ECCP256 9a pubkey.pem $ ykman piv generate-certificate --subject "yubico" 9a pubkey.pem \b Change the PIN from 123456 to 6543...
[ "Manage", "PIV", "Application", "." ]
3ac27bc59ae76a59db9d09a530494add2edbbabf
https://github.com/Yubico/yubikey-manager/blob/3ac27bc59ae76a59db9d09a530494add2edbbabf/ykman/cli/piv.py#L95-L120