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
9,900
romanz/trezor-agent
libagent/formats.py
export_public_key
def export_public_key(vk, label): """ Export public key to text format. The resulting string can be written into a .pub file or appended to the ~/.ssh/authorized_keys file. """ key_type, blob = serialize_verifying_key(vk) log.debug('fingerprint: %s', fingerprint(blob)) b64 = base64.b64e...
python
def export_public_key(vk, label): """ Export public key to text format. The resulting string can be written into a .pub file or appended to the ~/.ssh/authorized_keys file. """ key_type, blob = serialize_verifying_key(vk) log.debug('fingerprint: %s', fingerprint(blob)) b64 = base64.b64e...
[ "def", "export_public_key", "(", "vk", ",", "label", ")", ":", "key_type", ",", "blob", "=", "serialize_verifying_key", "(", "vk", ")", "log", ".", "debug", "(", "'fingerprint: %s'", ",", "fingerprint", "(", "blob", ")", ")", "b64", "=", "base64", ".", "...
Export public key to text format. The resulting string can be written into a .pub file or appended to the ~/.ssh/authorized_keys file.
[ "Export", "public", "key", "to", "text", "format", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/formats.py#L181-L191
9,901
romanz/trezor-agent
libagent/formats.py
import_public_key
def import_public_key(line): """Parse public key textual format, as saved at a .pub file.""" log.debug('loading SSH public key: %r', line) file_type, base64blob, name = line.split() blob = base64.b64decode(base64blob) result = parse_pubkey(blob) result['name'] = name.encode('utf-8') assert r...
python
def import_public_key(line): """Parse public key textual format, as saved at a .pub file.""" log.debug('loading SSH public key: %r', line) file_type, base64blob, name = line.split() blob = base64.b64decode(base64blob) result = parse_pubkey(blob) result['name'] = name.encode('utf-8') assert r...
[ "def", "import_public_key", "(", "line", ")", ":", "log", ".", "debug", "(", "'loading SSH public key: %r'", ",", "line", ")", "file_type", ",", "base64blob", ",", "name", "=", "line", ".", "split", "(", ")", "blob", "=", "base64", ".", "b64decode", "(", ...
Parse public key textual format, as saved at a .pub file.
[ "Parse", "public", "key", "textual", "format", "as", "saved", "at", "a", ".", "pub", "file", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/formats.py#L194-L203
9,902
romanz/trezor-agent
libagent/gpg/decode.py
parse_packets
def parse_packets(stream): """ Support iterative parsing of available GPG packets. See https://tools.ietf.org/html/rfc4880#section-4.2 for details. """ reader = util.Reader(stream) while True: try: value = reader.readfmt('B') except EOFError: return ...
python
def parse_packets(stream): """ Support iterative parsing of available GPG packets. See https://tools.ietf.org/html/rfc4880#section-4.2 for details. """ reader = util.Reader(stream) while True: try: value = reader.readfmt('B') except EOFError: return ...
[ "def", "parse_packets", "(", "stream", ")", ":", "reader", "=", "util", ".", "Reader", "(", "stream", ")", "while", "True", ":", "try", ":", "value", "=", "reader", ".", "readfmt", "(", "'B'", ")", "except", "EOFError", ":", "return", "log", ".", "de...
Support iterative parsing of available GPG packets. See https://tools.ietf.org/html/rfc4880#section-4.2 for details.
[ "Support", "iterative", "parsing", "of", "available", "GPG", "packets", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/decode.py#L215-L261
9,903
romanz/trezor-agent
libagent/gpg/decode.py
digest_packets
def digest_packets(packets, hasher): """Compute digest on specified packets, according to '_to_hash' field.""" data_to_hash = io.BytesIO() for p in packets: data_to_hash.write(p['_to_hash']) hasher.update(data_to_hash.getvalue()) return hasher.digest()
python
def digest_packets(packets, hasher): """Compute digest on specified packets, according to '_to_hash' field.""" data_to_hash = io.BytesIO() for p in packets: data_to_hash.write(p['_to_hash']) hasher.update(data_to_hash.getvalue()) return hasher.digest()
[ "def", "digest_packets", "(", "packets", ",", "hasher", ")", ":", "data_to_hash", "=", "io", ".", "BytesIO", "(", ")", "for", "p", "in", "packets", ":", "data_to_hash", ".", "write", "(", "p", "[", "'_to_hash'", "]", ")", "hasher", ".", "update", "(", ...
Compute digest on specified packets, according to '_to_hash' field.
[ "Compute", "digest", "on", "specified", "packets", "according", "to", "_to_hash", "field", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/decode.py#L264-L270
9,904
romanz/trezor-agent
libagent/gpg/decode.py
load_by_keygrip
def load_by_keygrip(pubkey_bytes, keygrip): """Return public key and first user ID for specified keygrip.""" stream = io.BytesIO(pubkey_bytes) packets = list(parse_packets(stream)) packets_per_pubkey = [] for p in packets: if p['type'] == 'pubkey': # Add a new packet list for eac...
python
def load_by_keygrip(pubkey_bytes, keygrip): """Return public key and first user ID for specified keygrip.""" stream = io.BytesIO(pubkey_bytes) packets = list(parse_packets(stream)) packets_per_pubkey = [] for p in packets: if p['type'] == 'pubkey': # Add a new packet list for eac...
[ "def", "load_by_keygrip", "(", "pubkey_bytes", ",", "keygrip", ")", ":", "stream", "=", "io", ".", "BytesIO", "(", "pubkey_bytes", ")", "packets", "=", "list", "(", "parse_packets", "(", "stream", ")", ")", "packets_per_pubkey", "=", "[", "]", "for", "p", ...
Return public key and first user ID for specified keygrip.
[ "Return", "public", "key", "and", "first", "user", "ID", "for", "specified", "keygrip", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/decode.py#L284-L300
9,905
romanz/trezor-agent
libagent/gpg/decode.py
load_signature
def load_signature(stream, original_data): """Load signature from stream, and compute GPG digest for verification.""" signature, = list(parse_packets((stream))) hash_alg = HASH_ALGORITHMS[signature['hash_alg']] digest = digest_packets([{'_to_hash': original_data}, signature], ...
python
def load_signature(stream, original_data): """Load signature from stream, and compute GPG digest for verification.""" signature, = list(parse_packets((stream))) hash_alg = HASH_ALGORITHMS[signature['hash_alg']] digest = digest_packets([{'_to_hash': original_data}, signature], ...
[ "def", "load_signature", "(", "stream", ",", "original_data", ")", ":", "signature", ",", "=", "list", "(", "parse_packets", "(", "(", "stream", ")", ")", ")", "hash_alg", "=", "HASH_ALGORITHMS", "[", "signature", "[", "'hash_alg'", "]", "]", "digest", "="...
Load signature from stream, and compute GPG digest for verification.
[ "Load", "signature", "from", "stream", "and", "compute", "GPG", "digest", "for", "verification", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/decode.py#L303-L310
9,906
romanz/trezor-agent
libagent/gpg/decode.py
remove_armor
def remove_armor(armored_data): """Decode armored data into its binary form.""" stream = io.BytesIO(armored_data) lines = stream.readlines()[3:-1] data = base64.b64decode(b''.join(lines)) payload, checksum = data[:-3], data[-3:] assert util.crc24(payload) == checksum return payload
python
def remove_armor(armored_data): """Decode armored data into its binary form.""" stream = io.BytesIO(armored_data) lines = stream.readlines()[3:-1] data = base64.b64decode(b''.join(lines)) payload, checksum = data[:-3], data[-3:] assert util.crc24(payload) == checksum return payload
[ "def", "remove_armor", "(", "armored_data", ")", ":", "stream", "=", "io", ".", "BytesIO", "(", "armored_data", ")", "lines", "=", "stream", ".", "readlines", "(", ")", "[", "3", ":", "-", "1", "]", "data", "=", "base64", ".", "b64decode", "(", "b''"...
Decode armored data into its binary form.
[ "Decode", "armored", "data", "into", "its", "binary", "form", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/decode.py#L313-L320
9,907
romanz/trezor-agent
libagent/server.py
remove_file
def remove_file(path, remove=os.remove, exists=os.path.exists): """Remove file, and raise OSError if still exists.""" try: remove(path) except OSError: if exists(path): raise
python
def remove_file(path, remove=os.remove, exists=os.path.exists): """Remove file, and raise OSError if still exists.""" try: remove(path) except OSError: if exists(path): raise
[ "def", "remove_file", "(", "path", ",", "remove", "=", "os", ".", "remove", ",", "exists", "=", "os", ".", "path", ".", "exists", ")", ":", "try", ":", "remove", "(", "path", ")", "except", "OSError", ":", "if", "exists", "(", "path", ")", ":", "...
Remove file, and raise OSError if still exists.
[ "Remove", "file", "and", "raise", "OSError", "if", "still", "exists", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/server.py#L14-L20
9,908
romanz/trezor-agent
libagent/server.py
unix_domain_socket_server
def unix_domain_socket_server(sock_path): """ Create UNIX-domain socket on specified path. Listen on it, and delete it after the generated context is over. """ log.debug('serving on %s', sock_path) remove_file(sock_path) server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) server...
python
def unix_domain_socket_server(sock_path): """ Create UNIX-domain socket on specified path. Listen on it, and delete it after the generated context is over. """ log.debug('serving on %s', sock_path) remove_file(sock_path) server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) server...
[ "def", "unix_domain_socket_server", "(", "sock_path", ")", ":", "log", ".", "debug", "(", "'serving on %s'", ",", "sock_path", ")", "remove_file", "(", "sock_path", ")", "server", "=", "socket", ".", "socket", "(", "socket", ".", "AF_UNIX", ",", "socket", "....
Create UNIX-domain socket on specified path. Listen on it, and delete it after the generated context is over.
[ "Create", "UNIX", "-", "domain", "socket", "on", "specified", "path", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/server.py#L24-L39
9,909
romanz/trezor-agent
libagent/server.py
handle_connection
def handle_connection(conn, handler, mutex): """ Handle a single connection using the specified protocol handler in a loop. Since this function may be called concurrently from server_thread, the specified mutex is used to synchronize the device handling. Exit when EOFError is raised. All other...
python
def handle_connection(conn, handler, mutex): """ Handle a single connection using the specified protocol handler in a loop. Since this function may be called concurrently from server_thread, the specified mutex is used to synchronize the device handling. Exit when EOFError is raised. All other...
[ "def", "handle_connection", "(", "conn", ",", "handler", ",", "mutex", ")", ":", "try", ":", "log", ".", "debug", "(", "'welcome agent'", ")", "with", "contextlib", ".", "closing", "(", "conn", ")", ":", "while", "True", ":", "msg", "=", "util", ".", ...
Handle a single connection using the specified protocol handler in a loop. Since this function may be called concurrently from server_thread, the specified mutex is used to synchronize the device handling. Exit when EOFError is raised. All other exceptions are logged as warnings.
[ "Handle", "a", "single", "connection", "using", "the", "specified", "protocol", "handler", "in", "a", "loop", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/server.py#L79-L100
9,910
romanz/trezor-agent
libagent/server.py
retry
def retry(func, exception_type, quit_event): """ Run the function, retrying when the specified exception_type occurs. Poll quit_event on each iteration, to be responsive to an external exit request. """ while True: if quit_event.is_set(): raise StopIteration try: ...
python
def retry(func, exception_type, quit_event): """ Run the function, retrying when the specified exception_type occurs. Poll quit_event on each iteration, to be responsive to an external exit request. """ while True: if quit_event.is_set(): raise StopIteration try: ...
[ "def", "retry", "(", "func", ",", "exception_type", ",", "quit_event", ")", ":", "while", "True", ":", "if", "quit_event", ".", "is_set", "(", ")", ":", "raise", "StopIteration", "try", ":", "return", "func", "(", ")", "except", "exception_type", ":", "p...
Run the function, retrying when the specified exception_type occurs. Poll quit_event on each iteration, to be responsive to an external exit request.
[ "Run", "the", "function", "retrying", "when", "the", "specified", "exception_type", "occurs", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/server.py#L103-L116
9,911
romanz/trezor-agent
libagent/server.py
spawn
def spawn(func, kwargs): """Spawn a thread, and join it after the context is over.""" t = threading.Thread(target=func, kwargs=kwargs) t.start() yield t.join()
python
def spawn(func, kwargs): """Spawn a thread, and join it after the context is over.""" t = threading.Thread(target=func, kwargs=kwargs) t.start() yield t.join()
[ "def", "spawn", "(", "func", ",", "kwargs", ")", ":", "t", "=", "threading", ".", "Thread", "(", "target", "=", "func", ",", "kwargs", "=", "kwargs", ")", "t", ".", "start", "(", ")", "yield", "t", ".", "join", "(", ")" ]
Spawn a thread, and join it after the context is over.
[ "Spawn", "a", "thread", "and", "join", "it", "after", "the", "context", "is", "over", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/server.py#L142-L147
9,912
romanz/trezor-agent
libagent/server.py
run_process
def run_process(command, environ): """ Run the specified process and wait until it finishes. Use environ dict for environment variables. """ log.info('running %r with %r', command, environ) env = dict(os.environ) env.update(environ) try: p = subprocess.Popen(args=command, env=en...
python
def run_process(command, environ): """ Run the specified process and wait until it finishes. Use environ dict for environment variables. """ log.info('running %r with %r', command, environ) env = dict(os.environ) env.update(environ) try: p = subprocess.Popen(args=command, env=en...
[ "def", "run_process", "(", "command", ",", "environ", ")", ":", "log", ".", "info", "(", "'running %r with %r'", ",", "command", ",", "environ", ")", "env", "=", "dict", "(", "os", ".", "environ", ")", "env", ".", "update", "(", "environ", ")", "try", ...
Run the specified process and wait until it finishes. Use environ dict for environment variables.
[ "Run", "the", "specified", "process", "and", "wait", "until", "it", "finishes", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/server.py#L150-L166
9,913
romanz/trezor-agent
libagent/gpg/keyring.py
check_output
def check_output(args, env=None, sp=subprocess): """Call an external binary and return its stdout.""" log.debug('calling %s with env %s', args, env) output = sp.check_output(args=args, env=env) log.debug('output: %r', output) return output
python
def check_output(args, env=None, sp=subprocess): """Call an external binary and return its stdout.""" log.debug('calling %s with env %s', args, env) output = sp.check_output(args=args, env=env) log.debug('output: %r', output) return output
[ "def", "check_output", "(", "args", ",", "env", "=", "None", ",", "sp", "=", "subprocess", ")", ":", "log", ".", "debug", "(", "'calling %s with env %s'", ",", "args", ",", "env", ")", "output", "=", "sp", ".", "check_output", "(", "args", "=", "args",...
Call an external binary and return its stdout.
[ "Call", "an", "external", "binary", "and", "return", "its", "stdout", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L17-L22
9,914
romanz/trezor-agent
libagent/gpg/keyring.py
get_agent_sock_path
def get_agent_sock_path(env=None, sp=subprocess): """Parse gpgconf output to find out GPG agent UNIX socket path.""" args = [util.which('gpgconf'), '--list-dirs'] output = check_output(args=args, env=env, sp=sp) lines = output.strip().split(b'\n') dirs = dict(line.split(b':', 1) for line in lines) ...
python
def get_agent_sock_path(env=None, sp=subprocess): """Parse gpgconf output to find out GPG agent UNIX socket path.""" args = [util.which('gpgconf'), '--list-dirs'] output = check_output(args=args, env=env, sp=sp) lines = output.strip().split(b'\n') dirs = dict(line.split(b':', 1) for line in lines) ...
[ "def", "get_agent_sock_path", "(", "env", "=", "None", ",", "sp", "=", "subprocess", ")", ":", "args", "=", "[", "util", ".", "which", "(", "'gpgconf'", ")", ",", "'--list-dirs'", "]", "output", "=", "check_output", "(", "args", "=", "args", ",", "env"...
Parse gpgconf output to find out GPG agent UNIX socket path.
[ "Parse", "gpgconf", "output", "to", "find", "out", "GPG", "agent", "UNIX", "socket", "path", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L25-L32
9,915
romanz/trezor-agent
libagent/gpg/keyring.py
connect_to_agent
def connect_to_agent(env=None, sp=subprocess): """Connect to GPG agent's UNIX socket.""" sock_path = get_agent_sock_path(sp=sp, env=env) # Make sure the original gpg-agent is running. check_output(args=['gpg-connect-agent', '/bye'], sp=sp) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) ...
python
def connect_to_agent(env=None, sp=subprocess): """Connect to GPG agent's UNIX socket.""" sock_path = get_agent_sock_path(sp=sp, env=env) # Make sure the original gpg-agent is running. check_output(args=['gpg-connect-agent', '/bye'], sp=sp) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) ...
[ "def", "connect_to_agent", "(", "env", "=", "None", ",", "sp", "=", "subprocess", ")", ":", "sock_path", "=", "get_agent_sock_path", "(", "sp", "=", "sp", ",", "env", "=", "env", ")", "# Make sure the original gpg-agent is running.", "check_output", "(", "args",...
Connect to GPG agent's UNIX socket.
[ "Connect", "to", "GPG", "agent", "s", "UNIX", "socket", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L35-L42
9,916
romanz/trezor-agent
libagent/gpg/keyring.py
sendline
def sendline(sock, msg, confidential=False): """Send a binary message, followed by EOL.""" log.debug('<- %r', ('<snip>' if confidential else msg)) sock.sendall(msg + b'\n')
python
def sendline(sock, msg, confidential=False): """Send a binary message, followed by EOL.""" log.debug('<- %r', ('<snip>' if confidential else msg)) sock.sendall(msg + b'\n')
[ "def", "sendline", "(", "sock", ",", "msg", ",", "confidential", "=", "False", ")", ":", "log", ".", "debug", "(", "'<- %r'", ",", "(", "'<snip>'", "if", "confidential", "else", "msg", ")", ")", "sock", ".", "sendall", "(", "msg", "+", "b'\\n'", ")" ...
Send a binary message, followed by EOL.
[ "Send", "a", "binary", "message", "followed", "by", "EOL", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L51-L54
9,917
romanz/trezor-agent
libagent/gpg/keyring.py
recvline
def recvline(sock): """Receive a single line from the socket.""" reply = io.BytesIO() while True: c = sock.recv(1) if not c: return None # socket is closed if c == b'\n': break reply.write(c) result = reply.getvalue() log.debug('-> %r', res...
python
def recvline(sock): """Receive a single line from the socket.""" reply = io.BytesIO() while True: c = sock.recv(1) if not c: return None # socket is closed if c == b'\n': break reply.write(c) result = reply.getvalue() log.debug('-> %r', res...
[ "def", "recvline", "(", "sock", ")", ":", "reply", "=", "io", ".", "BytesIO", "(", ")", "while", "True", ":", "c", "=", "sock", ".", "recv", "(", "1", ")", "if", "not", "c", ":", "return", "None", "# socket is closed", "if", "c", "==", "b'\\n'", ...
Receive a single line from the socket.
[ "Receive", "a", "single", "line", "from", "the", "socket", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L57-L72
9,918
romanz/trezor-agent
libagent/gpg/keyring.py
parse_term
def parse_term(s): """Parse single s-expr term from bytes.""" size, s = s.split(b':', 1) size = int(size) return s[:size], s[size:]
python
def parse_term(s): """Parse single s-expr term from bytes.""" size, s = s.split(b':', 1) size = int(size) return s[:size], s[size:]
[ "def", "parse_term", "(", "s", ")", ":", "size", ",", "s", "=", "s", ".", "split", "(", "b':'", ",", "1", ")", "size", "=", "int", "(", "size", ")", "return", "s", "[", ":", "size", "]", ",", "s", "[", "size", ":", "]" ]
Parse single s-expr term from bytes.
[ "Parse", "single", "s", "-", "expr", "term", "from", "bytes", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L97-L101
9,919
romanz/trezor-agent
libagent/gpg/keyring.py
parse
def parse(s): """Parse full s-expr from bytes.""" if s.startswith(b'('): s = s[1:] name, s = parse_term(s) values = [name] while not s.startswith(b')'): value, s = parse(s) values.append(value) return values, s[1:] return parse_term(s)
python
def parse(s): """Parse full s-expr from bytes.""" if s.startswith(b'('): s = s[1:] name, s = parse_term(s) values = [name] while not s.startswith(b')'): value, s = parse(s) values.append(value) return values, s[1:] return parse_term(s)
[ "def", "parse", "(", "s", ")", ":", "if", "s", ".", "startswith", "(", "b'('", ")", ":", "s", "=", "s", "[", "1", ":", "]", "name", ",", "s", "=", "parse_term", "(", "s", ")", "values", "=", "[", "name", "]", "while", "not", "s", ".", "star...
Parse full s-expr from bytes.
[ "Parse", "full", "s", "-", "expr", "from", "bytes", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L104-L115
9,920
romanz/trezor-agent
libagent/gpg/keyring.py
parse_sig
def parse_sig(sig): """Parse signature integer values from s-expr.""" label, sig = sig assert label == b'sig-val' algo_name = sig[0] parser = {b'rsa': _parse_rsa_sig, b'ecdsa': _parse_ecdsa_sig, b'eddsa': _parse_eddsa_sig, b'dsa': _parse_dsa_sig}[algo_name] ...
python
def parse_sig(sig): """Parse signature integer values from s-expr.""" label, sig = sig assert label == b'sig-val' algo_name = sig[0] parser = {b'rsa': _parse_rsa_sig, b'ecdsa': _parse_ecdsa_sig, b'eddsa': _parse_eddsa_sig, b'dsa': _parse_dsa_sig}[algo_name] ...
[ "def", "parse_sig", "(", "sig", ")", ":", "label", ",", "sig", "=", "sig", "assert", "label", "==", "b'sig-val'", "algo_name", "=", "sig", "[", "0", "]", "parser", "=", "{", "b'rsa'", ":", "_parse_rsa_sig", ",", "b'ecdsa'", ":", "_parse_ecdsa_sig", ",", ...
Parse signature integer values from s-expr.
[ "Parse", "signature", "integer", "values", "from", "s", "-", "expr", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L137-L146
9,921
romanz/trezor-agent
libagent/gpg/keyring.py
sign_digest
def sign_digest(sock, keygrip, digest, sp=subprocess, environ=None): """Sign a digest using specified key using GPG agent.""" hash_algo = 8 # SHA256 assert len(digest) == 32 assert communicate(sock, 'RESET').startswith(b'OK') ttyname = check_output(args=['tty'], sp=sp).strip() options = ['tty...
python
def sign_digest(sock, keygrip, digest, sp=subprocess, environ=None): """Sign a digest using specified key using GPG agent.""" hash_algo = 8 # SHA256 assert len(digest) == 32 assert communicate(sock, 'RESET').startswith(b'OK') ttyname = check_output(args=['tty'], sp=sp).strip() options = ['tty...
[ "def", "sign_digest", "(", "sock", ",", "keygrip", ",", "digest", ",", "sp", "=", "subprocess", ",", "environ", "=", "None", ")", ":", "hash_algo", "=", "8", "# SHA256", "assert", "len", "(", "digest", ")", "==", "32", "assert", "communicate", "(", "so...
Sign a digest using specified key using GPG agent.
[ "Sign", "a", "digest", "using", "specified", "key", "using", "GPG", "agent", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L149-L188
9,922
romanz/trezor-agent
libagent/gpg/keyring.py
get_gnupg_components
def get_gnupg_components(sp=subprocess): """Parse GnuPG components' paths.""" args = [util.which('gpgconf'), '--list-components'] output = check_output(args=args, sp=sp) components = dict(re.findall('(.*):.*:(.*)', output.decode('utf-8'))) log.debug('gpgconf --list-components: %s', components) r...
python
def get_gnupg_components(sp=subprocess): """Parse GnuPG components' paths.""" args = [util.which('gpgconf'), '--list-components'] output = check_output(args=args, sp=sp) components = dict(re.findall('(.*):.*:(.*)', output.decode('utf-8'))) log.debug('gpgconf --list-components: %s', components) r...
[ "def", "get_gnupg_components", "(", "sp", "=", "subprocess", ")", ":", "args", "=", "[", "util", ".", "which", "(", "'gpgconf'", ")", ",", "'--list-components'", "]", "output", "=", "check_output", "(", "args", "=", "args", ",", "sp", "=", "sp", ")", "...
Parse GnuPG components' paths.
[ "Parse", "GnuPG", "components", "paths", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L191-L197
9,923
romanz/trezor-agent
libagent/gpg/keyring.py
gpg_command
def gpg_command(args, env=None): """Prepare common GPG command line arguments.""" if env is None: env = os.environ cmd = get_gnupg_binary(neopg_binary=env.get('NEOPG_BINARY')) return [cmd] + args
python
def gpg_command(args, env=None): """Prepare common GPG command line arguments.""" if env is None: env = os.environ cmd = get_gnupg_binary(neopg_binary=env.get('NEOPG_BINARY')) return [cmd] + args
[ "def", "gpg_command", "(", "args", ",", "env", "=", "None", ")", ":", "if", "env", "is", "None", ":", "env", "=", "os", ".", "environ", "cmd", "=", "get_gnupg_binary", "(", "neopg_binary", "=", "env", ".", "get", "(", "'NEOPG_BINARY'", ")", ")", "ret...
Prepare common GPG command line arguments.
[ "Prepare", "common", "GPG", "command", "line", "arguments", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L208-L213
9,924
romanz/trezor-agent
libagent/gpg/keyring.py
export_public_key
def export_public_key(user_id, env=None, sp=subprocess): """Export GPG public key for specified `user_id`.""" args = gpg_command(['--export', user_id]) result = check_output(args=args, env=env, sp=sp) if not result: log.error('could not find public key %r in local GPG keyring', user_id) ...
python
def export_public_key(user_id, env=None, sp=subprocess): """Export GPG public key for specified `user_id`.""" args = gpg_command(['--export', user_id]) result = check_output(args=args, env=env, sp=sp) if not result: log.error('could not find public key %r in local GPG keyring', user_id) ...
[ "def", "export_public_key", "(", "user_id", ",", "env", "=", "None", ",", "sp", "=", "subprocess", ")", ":", "args", "=", "gpg_command", "(", "[", "'--export'", ",", "user_id", "]", ")", "result", "=", "check_output", "(", "args", "=", "args", ",", "en...
Export GPG public key for specified `user_id`.
[ "Export", "GPG", "public", "key", "for", "specified", "user_id", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L233-L240
9,925
romanz/trezor-agent
libagent/gpg/keyring.py
export_public_keys
def export_public_keys(env=None, sp=subprocess): """Export all GPG public keys.""" args = gpg_command(['--export']) result = check_output(args=args, env=env, sp=sp) if not result: raise KeyError('No GPG public keys found at env: {!r}'.format(env)) return result
python
def export_public_keys(env=None, sp=subprocess): """Export all GPG public keys.""" args = gpg_command(['--export']) result = check_output(args=args, env=env, sp=sp) if not result: raise KeyError('No GPG public keys found at env: {!r}'.format(env)) return result
[ "def", "export_public_keys", "(", "env", "=", "None", ",", "sp", "=", "subprocess", ")", ":", "args", "=", "gpg_command", "(", "[", "'--export'", "]", ")", "result", "=", "check_output", "(", "args", "=", "args", ",", "env", "=", "env", ",", "sp", "=...
Export all GPG public keys.
[ "Export", "all", "GPG", "public", "keys", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L243-L249
9,926
romanz/trezor-agent
libagent/gpg/keyring.py
create_agent_signer
def create_agent_signer(user_id): """Sign digest with existing GPG keys using gpg-agent tool.""" sock = connect_to_agent(env=os.environ) keygrip = get_keygrip(user_id) def sign(digest): """Sign the digest and return an ECDSA/RSA/DSA signature.""" return sign_digest(sock=sock, keygrip=ke...
python
def create_agent_signer(user_id): """Sign digest with existing GPG keys using gpg-agent tool.""" sock = connect_to_agent(env=os.environ) keygrip = get_keygrip(user_id) def sign(digest): """Sign the digest and return an ECDSA/RSA/DSA signature.""" return sign_digest(sock=sock, keygrip=ke...
[ "def", "create_agent_signer", "(", "user_id", ")", ":", "sock", "=", "connect_to_agent", "(", "env", "=", "os", ".", "environ", ")", "keygrip", "=", "get_keygrip", "(", "user_id", ")", "def", "sign", "(", "digest", ")", ":", "\"\"\"Sign the digest and return a...
Sign digest with existing GPG keys using gpg-agent tool.
[ "Sign", "digest", "with", "existing", "GPG", "keys", "using", "gpg", "-", "agent", "tool", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/keyring.py#L252-L261
9,927
romanz/trezor-agent
libagent/ssh/protocol.py
msg_name
def msg_name(code): """Convert integer message code into a string name.""" ids = {v: k for k, v in COMMANDS.items()} return ids[code]
python
def msg_name(code): """Convert integer message code into a string name.""" ids = {v: k for k, v in COMMANDS.items()} return ids[code]
[ "def", "msg_name", "(", "code", ")", ":", "ids", "=", "{", "v", ":", "k", "for", "k", ",", "v", "in", "COMMANDS", ".", "items", "(", ")", "}", "return", "ids", "[", "code", "]" ]
Convert integer message code into a string name.
[ "Convert", "integer", "message", "code", "into", "a", "string", "name", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/protocol.py#L51-L54
9,928
romanz/trezor-agent
libagent/ssh/protocol.py
_legacy_pubs
def _legacy_pubs(buf): """SSH v1 public keys are not supported.""" leftover = buf.read() if leftover: log.warning('skipping leftover: %r', leftover) code = util.pack('B', msg_code('SSH_AGENT_RSA_IDENTITIES_ANSWER')) num = util.pack('L', 0) # no SSH v1 keys return util.frame(code, num)
python
def _legacy_pubs(buf): """SSH v1 public keys are not supported.""" leftover = buf.read() if leftover: log.warning('skipping leftover: %r', leftover) code = util.pack('B', msg_code('SSH_AGENT_RSA_IDENTITIES_ANSWER')) num = util.pack('L', 0) # no SSH v1 keys return util.frame(code, num)
[ "def", "_legacy_pubs", "(", "buf", ")", ":", "leftover", "=", "buf", ".", "read", "(", ")", "if", "leftover", ":", "log", ".", "warning", "(", "'skipping leftover: %r'", ",", "leftover", ")", "code", "=", "util", ".", "pack", "(", "'B'", ",", "msg_code...
SSH v1 public keys are not supported.
[ "SSH", "v1", "public", "keys", "are", "not", "supported", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/protocol.py#L63-L70
9,929
romanz/trezor-agent
libagent/ssh/protocol.py
Handler.handle
def handle(self, msg): """Handle SSH message from the SSH client and return the response.""" debug_msg = ': {!r}'.format(msg) if self.debug else '' log.debug('request: %d bytes%s', len(msg), debug_msg) buf = io.BytesIO(msg) code, = util.recv(buf, '>B') if code not in self...
python
def handle(self, msg): """Handle SSH message from the SSH client and return the response.""" debug_msg = ': {!r}'.format(msg) if self.debug else '' log.debug('request: %d bytes%s', len(msg), debug_msg) buf = io.BytesIO(msg) code, = util.recv(buf, '>B') if code not in self...
[ "def", "handle", "(", "self", ",", "msg", ")", ":", "debug_msg", "=", "': {!r}'", ".", "format", "(", "msg", ")", "if", "self", ".", "debug", "else", "''", "log", ".", "debug", "(", "'request: %d bytes%s'", ",", "len", "(", "msg", ")", ",", "debug_ms...
Handle SSH message from the SSH client and return the response.
[ "Handle", "SSH", "message", "from", "the", "SSH", "client", "and", "return", "the", "response", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/protocol.py#L91-L106
9,930
romanz/trezor-agent
libagent/ssh/protocol.py
Handler.list_pubs
def list_pubs(self, buf): """SSH v2 public keys are serialized and returned.""" assert not buf.read() keys = self.conn.parse_public_keys() code = util.pack('B', msg_code('SSH2_AGENT_IDENTITIES_ANSWER')) num = util.pack('L', len(keys)) log.debug('available keys: %s', [k['n...
python
def list_pubs(self, buf): """SSH v2 public keys are serialized and returned.""" assert not buf.read() keys = self.conn.parse_public_keys() code = util.pack('B', msg_code('SSH2_AGENT_IDENTITIES_ANSWER')) num = util.pack('L', len(keys)) log.debug('available keys: %s', [k['n...
[ "def", "list_pubs", "(", "self", ",", "buf", ")", ":", "assert", "not", "buf", ".", "read", "(", ")", "keys", "=", "self", ".", "conn", ".", "parse_public_keys", "(", ")", "code", "=", "util", ".", "pack", "(", "'B'", ",", "msg_code", "(", "'SSH2_A...
SSH v2 public keys are serialized and returned.
[ "SSH", "v2", "public", "keys", "are", "serialized", "and", "returned", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/protocol.py#L108-L118
9,931
romanz/trezor-agent
libagent/ssh/protocol.py
Handler.sign_message
def sign_message(self, buf): """ SSH v2 public key authentication is performed. If the required key is not supported, raise KeyError If the signature is invalid, raise ValueError """ key = formats.parse_pubkey(util.read_frame(buf)) log.debug('looking for %s', key...
python
def sign_message(self, buf): """ SSH v2 public key authentication is performed. If the required key is not supported, raise KeyError If the signature is invalid, raise ValueError """ key = formats.parse_pubkey(util.read_frame(buf)) log.debug('looking for %s', key...
[ "def", "sign_message", "(", "self", ",", "buf", ")", ":", "key", "=", "formats", ".", "parse_pubkey", "(", "util", ".", "read_frame", "(", "buf", ")", ")", "log", ".", "debug", "(", "'looking for %s'", ",", "key", "[", "'fingerprint'", "]", ")", "blob"...
SSH v2 public key authentication is performed. If the required key is not supported, raise KeyError If the signature is invalid, raise ValueError
[ "SSH", "v2", "public", "key", "authentication", "is", "performed", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/protocol.py#L120-L160
9,932
romanz/trezor-agent
libagent/util.py
recv
def recv(conn, size): """ Receive bytes from connection socket or stream. If size is struct.calcsize()-compatible format, use it to unpack the data. Otherwise, return the plain blob as bytes. """ try: fmt = size size = struct.calcsize(fmt) except TypeError: fmt = Non...
python
def recv(conn, size): """ Receive bytes from connection socket or stream. If size is struct.calcsize()-compatible format, use it to unpack the data. Otherwise, return the plain blob as bytes. """ try: fmt = size size = struct.calcsize(fmt) except TypeError: fmt = Non...
[ "def", "recv", "(", "conn", ",", "size", ")", ":", "try", ":", "fmt", "=", "size", "size", "=", "struct", ".", "calcsize", "(", "fmt", ")", "except", "TypeError", ":", "fmt", "=", "None", "try", ":", "_read", "=", "conn", ".", "recv", "except", "...
Receive bytes from connection socket or stream. If size is struct.calcsize()-compatible format, use it to unpack the data. Otherwise, return the plain blob as bytes.
[ "Receive", "bytes", "from", "connection", "socket", "or", "stream", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L18-L46
9,933
romanz/trezor-agent
libagent/util.py
bytes2num
def bytes2num(s): """Convert MSB-first bytes to an unsigned integer.""" res = 0 for i, c in enumerate(reversed(bytearray(s))): res += c << (i * 8) return res
python
def bytes2num(s): """Convert MSB-first bytes to an unsigned integer.""" res = 0 for i, c in enumerate(reversed(bytearray(s))): res += c << (i * 8) return res
[ "def", "bytes2num", "(", "s", ")", ":", "res", "=", "0", "for", "i", ",", "c", "in", "enumerate", "(", "reversed", "(", "bytearray", "(", "s", ")", ")", ")", ":", "res", "+=", "c", "<<", "(", "i", "*", "8", ")", "return", "res" ]
Convert MSB-first bytes to an unsigned integer.
[ "Convert", "MSB", "-", "first", "bytes", "to", "an", "unsigned", "integer", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L55-L60
9,934
romanz/trezor-agent
libagent/util.py
num2bytes
def num2bytes(value, size): """Convert an unsigned integer to MSB-first bytes with specified size.""" res = [] for _ in range(size): res.append(value & 0xFF) value = value >> 8 assert value == 0 return bytes(bytearray(list(reversed(res))))
python
def num2bytes(value, size): """Convert an unsigned integer to MSB-first bytes with specified size.""" res = [] for _ in range(size): res.append(value & 0xFF) value = value >> 8 assert value == 0 return bytes(bytearray(list(reversed(res))))
[ "def", "num2bytes", "(", "value", ",", "size", ")", ":", "res", "=", "[", "]", "for", "_", "in", "range", "(", "size", ")", ":", "res", ".", "append", "(", "value", "&", "0xFF", ")", "value", "=", "value", ">>", "8", "assert", "value", "==", "0...
Convert an unsigned integer to MSB-first bytes with specified size.
[ "Convert", "an", "unsigned", "integer", "to", "MSB", "-", "first", "bytes", "with", "specified", "size", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L63-L70
9,935
romanz/trezor-agent
libagent/util.py
frame
def frame(*msgs): """Serialize MSB-first length-prefixed frame.""" res = io.BytesIO() for msg in msgs: res.write(msg) msg = res.getvalue() return pack('L', len(msg)) + msg
python
def frame(*msgs): """Serialize MSB-first length-prefixed frame.""" res = io.BytesIO() for msg in msgs: res.write(msg) msg = res.getvalue() return pack('L', len(msg)) + msg
[ "def", "frame", "(", "*", "msgs", ")", ":", "res", "=", "io", ".", "BytesIO", "(", ")", "for", "msg", "in", "msgs", ":", "res", ".", "write", "(", "msg", ")", "msg", "=", "res", ".", "getvalue", "(", ")", "return", "pack", "(", "'L'", ",", "l...
Serialize MSB-first length-prefixed frame.
[ "Serialize", "MSB", "-", "first", "length", "-", "prefixed", "frame", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L78-L84
9,936
romanz/trezor-agent
libagent/util.py
split_bits
def split_bits(value, *bits): """ Split integer value into list of ints, according to `bits` list. For example, split_bits(0x1234, 4, 8, 4) == [0x1, 0x23, 0x4] """ result = [] for b in reversed(bits): mask = (1 << b) - 1 result.append(value & mask) value = value >> b ...
python
def split_bits(value, *bits): """ Split integer value into list of ints, according to `bits` list. For example, split_bits(0x1234, 4, 8, 4) == [0x1, 0x23, 0x4] """ result = [] for b in reversed(bits): mask = (1 << b) - 1 result.append(value & mask) value = value >> b ...
[ "def", "split_bits", "(", "value", ",", "*", "bits", ")", ":", "result", "=", "[", "]", "for", "b", "in", "reversed", "(", "bits", ")", ":", "mask", "=", "(", "1", "<<", "b", ")", "-", "1", "result", ".", "append", "(", "value", "&", "mask", ...
Split integer value into list of ints, according to `bits` list. For example, split_bits(0x1234, 4, 8, 4) == [0x1, 0x23, 0x4]
[ "Split", "integer", "value", "into", "list", "of", "ints", "according", "to", "bits", "list", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L115-L129
9,937
romanz/trezor-agent
libagent/util.py
readfmt
def readfmt(stream, fmt): """Read and unpack an object from stream, using a struct format string.""" size = struct.calcsize(fmt) blob = stream.read(size) return struct.unpack(fmt, blob)
python
def readfmt(stream, fmt): """Read and unpack an object from stream, using a struct format string.""" size = struct.calcsize(fmt) blob = stream.read(size) return struct.unpack(fmt, blob)
[ "def", "readfmt", "(", "stream", ",", "fmt", ")", ":", "size", "=", "struct", ".", "calcsize", "(", "fmt", ")", "blob", "=", "stream", ".", "read", "(", "size", ")", "return", "struct", ".", "unpack", "(", "fmt", ",", "blob", ")" ]
Read and unpack an object from stream, using a struct format string.
[ "Read", "and", "unpack", "an", "object", "from", "stream", "using", "a", "struct", "format", "string", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L132-L136
9,938
romanz/trezor-agent
libagent/util.py
setup_logging
def setup_logging(verbosity, filename=None): """Configure logging for this tool.""" levels = [logging.WARNING, logging.INFO, logging.DEBUG] level = levels[min(verbosity, len(levels) - 1)] logging.root.setLevel(level) fmt = logging.Formatter('%(asctime)s %(levelname)-12s %(message)-100s ' ...
python
def setup_logging(verbosity, filename=None): """Configure logging for this tool.""" levels = [logging.WARNING, logging.INFO, logging.DEBUG] level = levels[min(verbosity, len(levels) - 1)] logging.root.setLevel(level) fmt = logging.Formatter('%(asctime)s %(levelname)-12s %(message)-100s ' ...
[ "def", "setup_logging", "(", "verbosity", ",", "filename", "=", "None", ")", ":", "levels", "=", "[", "logging", ".", "WARNING", ",", "logging", ".", "INFO", ",", "logging", ".", "DEBUG", "]", "level", "=", "levels", "[", "min", "(", "verbosity", ",", ...
Configure logging for this tool.
[ "Configure", "logging", "for", "this", "tool", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L183-L198
9,939
romanz/trezor-agent
libagent/util.py
which
def which(cmd): """Return full path to specified command, or raise OSError if missing.""" try: # For Python 3 from shutil import which as _which except ImportError: # For Python 2 from backports.shutil_which import which as _which # pylint: disable=relative-import full_p...
python
def which(cmd): """Return full path to specified command, or raise OSError if missing.""" try: # For Python 3 from shutil import which as _which except ImportError: # For Python 2 from backports.shutil_which import which as _which # pylint: disable=relative-import full_p...
[ "def", "which", "(", "cmd", ")", ":", "try", ":", "# For Python 3", "from", "shutil", "import", "which", "as", "_which", "except", "ImportError", ":", "# For Python 2", "from", "backports", ".", "shutil_which", "import", "which", "as", "_which", "# pylint: disab...
Return full path to specified command, or raise OSError if missing.
[ "Return", "full", "path", "to", "specified", "command", "or", "raise", "OSError", "if", "missing", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L238-L250
9,940
romanz/trezor-agent
libagent/util.py
Reader.readfmt
def readfmt(self, fmt): """Read a specified object, using a struct format string.""" size = struct.calcsize(fmt) blob = self.read(size) obj, = struct.unpack(fmt, blob) return obj
python
def readfmt(self, fmt): """Read a specified object, using a struct format string.""" size = struct.calcsize(fmt) blob = self.read(size) obj, = struct.unpack(fmt, blob) return obj
[ "def", "readfmt", "(", "self", ",", "fmt", ")", ":", "size", "=", "struct", ".", "calcsize", "(", "fmt", ")", "blob", "=", "self", ".", "read", "(", "size", ")", "obj", ",", "=", "struct", ".", "unpack", "(", "fmt", ",", "blob", ")", "return", ...
Read a specified object, using a struct format string.
[ "Read", "a", "specified", "object", "using", "a", "struct", "format", "string", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L157-L162
9,941
romanz/trezor-agent
libagent/util.py
Reader.read
def read(self, size=None): """Read `size` bytes from stream.""" blob = self.s.read(size) if size is not None and len(blob) < size: raise EOFError if self._captured: self._captured.write(blob) return blob
python
def read(self, size=None): """Read `size` bytes from stream.""" blob = self.s.read(size) if size is not None and len(blob) < size: raise EOFError if self._captured: self._captured.write(blob) return blob
[ "def", "read", "(", "self", ",", "size", "=", "None", ")", ":", "blob", "=", "self", ".", "s", ".", "read", "(", "size", ")", "if", "size", "is", "not", "None", "and", "len", "(", "blob", ")", "<", "size", ":", "raise", "EOFError", "if", "self"...
Read `size` bytes from stream.
[ "Read", "size", "bytes", "from", "stream", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L164-L171
9,942
romanz/trezor-agent
libagent/util.py
ExpiringCache.get
def get(self): """Returns existing value, or None if deadline has expired.""" if self.timer() > self.deadline: self.value = None return self.value
python
def get(self): """Returns existing value, or None if deadline has expired.""" if self.timer() > self.deadline: self.value = None return self.value
[ "def", "get", "(", "self", ")", ":", "if", "self", ".", "timer", "(", ")", ">", "self", ".", "deadline", ":", "self", ".", "value", "=", "None", "return", "self", ".", "value" ]
Returns existing value, or None if deadline has expired.
[ "Returns", "existing", "value", "or", "None", "if", "deadline", "has", "expired", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L271-L275
9,943
romanz/trezor-agent
libagent/util.py
ExpiringCache.set
def set(self, value): """Set new value and reset the deadline for expiration.""" self.deadline = self.timer() + self.duration self.value = value
python
def set(self, value): """Set new value and reset the deadline for expiration.""" self.deadline = self.timer() + self.duration self.value = value
[ "def", "set", "(", "self", ",", "value", ")", ":", "self", ".", "deadline", "=", "self", ".", "timer", "(", ")", "+", "self", ".", "duration", "self", ".", "value", "=", "value" ]
Set new value and reset the deadline for expiration.
[ "Set", "new", "value", "and", "reset", "the", "deadline", "for", "expiration", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/util.py#L277-L280
9,944
romanz/trezor-agent
libagent/gpg/agent.py
sig_encode
def sig_encode(r, s): """Serialize ECDSA signature data into GPG S-expression.""" r = util.assuan_serialize(util.num2bytes(r, 32)) s = util.assuan_serialize(util.num2bytes(s, 32)) return b'(7:sig-val(5:ecdsa(1:r32:' + r + b')(1:s32:' + s + b')))'
python
def sig_encode(r, s): """Serialize ECDSA signature data into GPG S-expression.""" r = util.assuan_serialize(util.num2bytes(r, 32)) s = util.assuan_serialize(util.num2bytes(s, 32)) return b'(7:sig-val(5:ecdsa(1:r32:' + r + b')(1:s32:' + s + b')))'
[ "def", "sig_encode", "(", "r", ",", "s", ")", ":", "r", "=", "util", ".", "assuan_serialize", "(", "util", ".", "num2bytes", "(", "r", ",", "32", ")", ")", "s", "=", "util", ".", "assuan_serialize", "(", "util", ".", "num2bytes", "(", "s", ",", "...
Serialize ECDSA signature data into GPG S-expression.
[ "Serialize", "ECDSA", "signature", "data", "into", "GPG", "S", "-", "expression", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L24-L28
9,945
romanz/trezor-agent
libagent/gpg/agent.py
parse_ecdh
def parse_ecdh(line): """Parse ECDH request and return remote public key.""" prefix, line = line.split(b' ', 1) assert prefix == b'D' exp, leftover = keyring.parse(keyring.unescape(line)) log.debug('ECDH s-exp: %r', exp) assert not leftover label, exp = exp assert label == b'enc-val' ...
python
def parse_ecdh(line): """Parse ECDH request and return remote public key.""" prefix, line = line.split(b' ', 1) assert prefix == b'D' exp, leftover = keyring.parse(keyring.unescape(line)) log.debug('ECDH s-exp: %r', exp) assert not leftover label, exp = exp assert label == b'enc-val' ...
[ "def", "parse_ecdh", "(", "line", ")", ":", "prefix", ",", "line", "=", "line", ".", "split", "(", "b' '", ",", "1", ")", "assert", "prefix", "==", "b'D'", "exp", ",", "leftover", "=", "keyring", ".", "parse", "(", "keyring", ".", "unescape", "(", ...
Parse ECDH request and return remote public key.
[ "Parse", "ECDH", "request", "and", "return", "remote", "public", "key", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L37-L49
9,946
romanz/trezor-agent
libagent/gpg/agent.py
Handler.handle_getinfo
def handle_getinfo(self, conn, args): """Handle some of the GETINFO messages.""" result = None if args[0] == b'version': result = self.version elif args[0] == b's2k_count': # Use highest number of S2K iterations. # https://www.gnupg.org/documentation/m...
python
def handle_getinfo(self, conn, args): """Handle some of the GETINFO messages.""" result = None if args[0] == b'version': result = self.version elif args[0] == b's2k_count': # Use highest number of S2K iterations. # https://www.gnupg.org/documentation/m...
[ "def", "handle_getinfo", "(", "self", ",", "conn", ",", "args", ")", ":", "result", "=", "None", "if", "args", "[", "0", "]", "==", "b'version'", ":", "result", "=", "self", ".", "version", "elif", "args", "[", "0", "]", "==", "b's2k_count'", ":", ...
Handle some of the GETINFO messages.
[ "Handle", "some", "of", "the", "GETINFO", "messages", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L129-L143
9,947
romanz/trezor-agent
libagent/gpg/agent.py
Handler.handle_scd
def handle_scd(self, conn, args): """No support for smart-card device protocol.""" reply = { (b'GETINFO', b'version'): self.version, }.get(args) if reply is None: raise AgentError(b'ERR 100696144 No such device <SCD>') keyring.sendline(conn, b'D ' + reply)
python
def handle_scd(self, conn, args): """No support for smart-card device protocol.""" reply = { (b'GETINFO', b'version'): self.version, }.get(args) if reply is None: raise AgentError(b'ERR 100696144 No such device <SCD>') keyring.sendline(conn, b'D ' + reply)
[ "def", "handle_scd", "(", "self", ",", "conn", ",", "args", ")", ":", "reply", "=", "{", "(", "b'GETINFO'", ",", "b'version'", ")", ":", "self", ".", "version", ",", "}", ".", "get", "(", "args", ")", "if", "reply", "is", "None", ":", "raise", "A...
No support for smart-card device protocol.
[ "No", "support", "for", "smart", "-", "card", "device", "protocol", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L145-L152
9,948
romanz/trezor-agent
libagent/gpg/agent.py
Handler.get_identity
def get_identity(self, keygrip): """ Returns device.interface.Identity that matches specified keygrip. In case of missing keygrip, KeyError will be raised. """ keygrip_bytes = binascii.unhexlify(keygrip) pubkey_dict, user_ids = decode.load_by_keygrip( pubkey_...
python
def get_identity(self, keygrip): """ Returns device.interface.Identity that matches specified keygrip. In case of missing keygrip, KeyError will be raised. """ keygrip_bytes = binascii.unhexlify(keygrip) pubkey_dict, user_ids = decode.load_by_keygrip( pubkey_...
[ "def", "get_identity", "(", "self", ",", "keygrip", ")", ":", "keygrip_bytes", "=", "binascii", ".", "unhexlify", "(", "keygrip", ")", "pubkey_dict", ",", "user_ids", "=", "decode", ".", "load_by_keygrip", "(", "pubkey_bytes", "=", "self", ".", "pubkey_bytes",...
Returns device.interface.Identity that matches specified keygrip. In case of missing keygrip, KeyError will be raised.
[ "Returns", "device", ".", "interface", ".", "Identity", "that", "matches", "specified", "keygrip", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L155-L176
9,949
romanz/trezor-agent
libagent/gpg/agent.py
Handler.pksign
def pksign(self, conn): """Sign a message digest using a private EC key.""" log.debug('signing %r digest (algo #%s)', self.digest, self.algo) identity = self.get_identity(keygrip=self.keygrip) r, s = self.client.sign(identity=identity, digest=binascii.unhe...
python
def pksign(self, conn): """Sign a message digest using a private EC key.""" log.debug('signing %r digest (algo #%s)', self.digest, self.algo) identity = self.get_identity(keygrip=self.keygrip) r, s = self.client.sign(identity=identity, digest=binascii.unhe...
[ "def", "pksign", "(", "self", ",", "conn", ")", ":", "log", ".", "debug", "(", "'signing %r digest (algo #%s)'", ",", "self", ".", "digest", ",", "self", ".", "algo", ")", "identity", "=", "self", ".", "get_identity", "(", "keygrip", "=", "self", ".", ...
Sign a message digest using a private EC key.
[ "Sign", "a", "message", "digest", "using", "a", "private", "EC", "key", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L178-L186
9,950
romanz/trezor-agent
libagent/gpg/agent.py
Handler.pkdecrypt
def pkdecrypt(self, conn): """Handle decryption using ECDH.""" for msg in [b'S INQUIRE_MAXLEN 4096', b'INQUIRE CIPHERTEXT']: keyring.sendline(conn, msg) line = keyring.recvline(conn) assert keyring.recvline(conn) == b'END' remote_pubkey = parse_ecdh(line) id...
python
def pkdecrypt(self, conn): """Handle decryption using ECDH.""" for msg in [b'S INQUIRE_MAXLEN 4096', b'INQUIRE CIPHERTEXT']: keyring.sendline(conn, msg) line = keyring.recvline(conn) assert keyring.recvline(conn) == b'END' remote_pubkey = parse_ecdh(line) id...
[ "def", "pkdecrypt", "(", "self", ",", "conn", ")", ":", "for", "msg", "in", "[", "b'S INQUIRE_MAXLEN 4096'", ",", "b'INQUIRE CIPHERTEXT'", "]", ":", "keyring", ".", "sendline", "(", "conn", ",", "msg", ")", "line", "=", "keyring", ".", "recvline", "(", "...
Handle decryption using ECDH.
[ "Handle", "decryption", "using", "ECDH", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L188-L199
9,951
romanz/trezor-agent
libagent/gpg/agent.py
Handler.have_key
def have_key(self, *keygrips): """Check if any keygrip corresponds to a TREZOR-based key.""" for keygrip in keygrips: try: self.get_identity(keygrip=keygrip) break except KeyError as e: log.warning('HAVEKEY(%s) failed: %s', keygrip,...
python
def have_key(self, *keygrips): """Check if any keygrip corresponds to a TREZOR-based key.""" for keygrip in keygrips: try: self.get_identity(keygrip=keygrip) break except KeyError as e: log.warning('HAVEKEY(%s) failed: %s', keygrip,...
[ "def", "have_key", "(", "self", ",", "*", "keygrips", ")", ":", "for", "keygrip", "in", "keygrips", ":", "try", ":", "self", ".", "get_identity", "(", "keygrip", "=", "keygrip", ")", "break", "except", "KeyError", "as", "e", ":", "log", ".", "warning",...
Check if any keygrip corresponds to a TREZOR-based key.
[ "Check", "if", "any", "keygrip", "corresponds", "to", "a", "TREZOR", "-", "based", "key", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L201-L210
9,952
romanz/trezor-agent
libagent/gpg/agent.py
Handler.set_hash
def set_hash(self, algo, digest): """Set algorithm ID and hexadecimal digest for next operation.""" self.algo = algo self.digest = digest
python
def set_hash(self, algo, digest): """Set algorithm ID and hexadecimal digest for next operation.""" self.algo = algo self.digest = digest
[ "def", "set_hash", "(", "self", ",", "algo", ",", "digest", ")", ":", "self", ".", "algo", "=", "algo", "self", ".", "digest", "=", "digest" ]
Set algorithm ID and hexadecimal digest for next operation.
[ "Set", "algorithm", "ID", "and", "hexadecimal", "digest", "for", "next", "operation", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L216-L219
9,953
romanz/trezor-agent
libagent/gpg/agent.py
Handler.handle
def handle(self, conn): """Handle connection from GPG binary using the ASSUAN protocol.""" keyring.sendline(conn, b'OK') for line in keyring.iterlines(conn): parts = line.split(b' ') command = parts[0] args = tuple(parts[1:]) if command == b'BYE':...
python
def handle(self, conn): """Handle connection from GPG binary using the ASSUAN protocol.""" keyring.sendline(conn, b'OK') for line in keyring.iterlines(conn): parts = line.split(b' ') command = parts[0] args = tuple(parts[1:]) if command == b'BYE':...
[ "def", "handle", "(", "self", ",", "conn", ")", ":", "keyring", ".", "sendline", "(", "conn", ",", "b'OK'", ")", "for", "line", "in", "keyring", ".", "iterlines", "(", "conn", ")", ":", "parts", "=", "line", ".", "split", "(", "b' '", ")", "command...
Handle connection from GPG binary using the ASSUAN protocol.
[ "Handle", "connection", "from", "GPG", "binary", "using", "the", "ASSUAN", "protocol", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L221-L247
9,954
romanz/trezor-agent
libagent/device/fake_device.py
FakeDevice.connect
def connect(self): """Return "dummy" connection.""" log.critical('NEVER USE THIS CODE FOR REAL-LIFE USE-CASES!!!') log.critical('ONLY FOR DEBUGGING AND TESTING!!!') # The code below uses HARD-CODED secret key - and should be used ONLY # for GnuPG integration tests (e.g. when no r...
python
def connect(self): """Return "dummy" connection.""" log.critical('NEVER USE THIS CODE FOR REAL-LIFE USE-CASES!!!') log.critical('ONLY FOR DEBUGGING AND TESTING!!!') # The code below uses HARD-CODED secret key - and should be used ONLY # for GnuPG integration tests (e.g. when no r...
[ "def", "connect", "(", "self", ")", ":", "log", ".", "critical", "(", "'NEVER USE THIS CODE FOR REAL-LIFE USE-CASES!!!'", ")", "log", ".", "critical", "(", "'ONLY FOR DEBUGGING AND TESTING!!!'", ")", "# The code below uses HARD-CODED secret key - and should be used ONLY", "# fo...
Return "dummy" connection.
[ "Return", "dummy", "connection", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/fake_device.py#L29-L40
9,955
romanz/trezor-agent
libagent/gpg/client.py
create_identity
def create_identity(user_id, curve_name): """Create GPG identity for hardware device.""" result = interface.Identity(identity_str='gpg://', curve_name=curve_name) result.identity_dict['host'] = user_id return result
python
def create_identity(user_id, curve_name): """Create GPG identity for hardware device.""" result = interface.Identity(identity_str='gpg://', curve_name=curve_name) result.identity_dict['host'] = user_id return result
[ "def", "create_identity", "(", "user_id", ",", "curve_name", ")", ":", "result", "=", "interface", ".", "Identity", "(", "identity_str", "=", "'gpg://'", ",", "curve_name", "=", "curve_name", ")", "result", ".", "identity_dict", "[", "'host'", "]", "=", "use...
Create GPG identity for hardware device.
[ "Create", "GPG", "identity", "for", "hardware", "device", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/client.py#L11-L15
9,956
romanz/trezor-agent
libagent/gpg/client.py
Client.pubkey
def pubkey(self, identity, ecdh=False): """Return public key as VerifyingKey object.""" with self.device: pubkey = self.device.pubkey(ecdh=ecdh, identity=identity) return formats.decompress_pubkey( pubkey=pubkey, curve_name=identity.curve_name)
python
def pubkey(self, identity, ecdh=False): """Return public key as VerifyingKey object.""" with self.device: pubkey = self.device.pubkey(ecdh=ecdh, identity=identity) return formats.decompress_pubkey( pubkey=pubkey, curve_name=identity.curve_name)
[ "def", "pubkey", "(", "self", ",", "identity", ",", "ecdh", "=", "False", ")", ":", "with", "self", ".", "device", ":", "pubkey", "=", "self", ".", "device", ".", "pubkey", "(", "ecdh", "=", "ecdh", ",", "identity", "=", "identity", ")", "return", ...
Return public key as VerifyingKey object.
[ "Return", "public", "key", "as", "VerifyingKey", "object", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/client.py#L25-L30
9,957
romanz/trezor-agent
libagent/gpg/client.py
Client.sign
def sign(self, identity, digest): """Sign the digest and return a serialized signature.""" log.info('please confirm GPG signature on %s for "%s"...', self.device, identity.to_string()) if identity.curve_name == formats.CURVE_NIST256: digest = digest[:32] # sign the ...
python
def sign(self, identity, digest): """Sign the digest and return a serialized signature.""" log.info('please confirm GPG signature on %s for "%s"...', self.device, identity.to_string()) if identity.curve_name == formats.CURVE_NIST256: digest = digest[:32] # sign the ...
[ "def", "sign", "(", "self", ",", "identity", ",", "digest", ")", ":", "log", ".", "info", "(", "'please confirm GPG signature on %s for \"%s\"...'", ",", "self", ".", "device", ",", "identity", ".", "to_string", "(", ")", ")", "if", "identity", ".", "curve_n...
Sign the digest and return a serialized signature.
[ "Sign", "the", "digest", "and", "return", "a", "serialized", "signature", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/client.py#L32-L41
9,958
romanz/trezor-agent
libagent/gpg/client.py
Client.ecdh
def ecdh(self, identity, pubkey): """Derive shared secret using ECDH from remote public key.""" log.info('please confirm GPG decryption on %s for "%s"...', self.device, identity.to_string()) with self.device: return self.device.ecdh(pubkey=pubkey, identity=identity)
python
def ecdh(self, identity, pubkey): """Derive shared secret using ECDH from remote public key.""" log.info('please confirm GPG decryption on %s for "%s"...', self.device, identity.to_string()) with self.device: return self.device.ecdh(pubkey=pubkey, identity=identity)
[ "def", "ecdh", "(", "self", ",", "identity", ",", "pubkey", ")", ":", "log", ".", "info", "(", "'please confirm GPG decryption on %s for \"%s\"...'", ",", "self", ".", "device", ",", "identity", ".", "to_string", "(", ")", ")", "with", "self", ".", "device",...
Derive shared secret using ECDH from remote public key.
[ "Derive", "shared", "secret", "using", "ECDH", "from", "remote", "public", "key", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/client.py#L43-L48
9,959
romanz/trezor-agent
libagent/device/trezor.py
Trezor.connect
def connect(self): """Enumerate and connect to the first available interface.""" transport = self._defs.find_device() if not transport: raise interface.NotFoundError('{} not connected'.format(self)) log.debug('using transport: %s', transport) for _ in range(5): # Re...
python
def connect(self): """Enumerate and connect to the first available interface.""" transport = self._defs.find_device() if not transport: raise interface.NotFoundError('{} not connected'.format(self)) log.debug('using transport: %s', transport) for _ in range(5): # Re...
[ "def", "connect", "(", "self", ")", ":", "transport", "=", "self", ".", "_defs", ".", "find_device", "(", ")", "if", "not", "transport", ":", "raise", "interface", ".", "NotFoundError", "(", "'{} not connected'", ".", "format", "(", "self", ")", ")", "lo...
Enumerate and connect to the first available interface.
[ "Enumerate", "and", "connect", "to", "the", "first", "available", "interface", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/trezor.py#L47-L69
9,960
romanz/trezor-agent
libagent/device/interface.py
string_to_identity
def string_to_identity(identity_str): """Parse string into Identity dictionary.""" m = _identity_regexp.match(identity_str) result = m.groupdict() log.debug('parsed identity: %s', result) return {k: v for k, v in result.items() if v}
python
def string_to_identity(identity_str): """Parse string into Identity dictionary.""" m = _identity_regexp.match(identity_str) result = m.groupdict() log.debug('parsed identity: %s', result) return {k: v for k, v in result.items() if v}
[ "def", "string_to_identity", "(", "identity_str", ")", ":", "m", "=", "_identity_regexp", ".", "match", "(", "identity_str", ")", "result", "=", "m", ".", "groupdict", "(", ")", "log", ".", "debug", "(", "'parsed identity: %s'", ",", "result", ")", "return",...
Parse string into Identity dictionary.
[ "Parse", "string", "into", "Identity", "dictionary", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/interface.py#L26-L31
9,961
romanz/trezor-agent
libagent/device/interface.py
identity_to_string
def identity_to_string(identity_dict): """Dump Identity dictionary into its string representation.""" result = [] if identity_dict.get('proto'): result.append(identity_dict['proto'] + '://') if identity_dict.get('user'): result.append(identity_dict['user'] + '@') result.append(identi...
python
def identity_to_string(identity_dict): """Dump Identity dictionary into its string representation.""" result = [] if identity_dict.get('proto'): result.append(identity_dict['proto'] + '://') if identity_dict.get('user'): result.append(identity_dict['user'] + '@') result.append(identi...
[ "def", "identity_to_string", "(", "identity_dict", ")", ":", "result", "=", "[", "]", "if", "identity_dict", ".", "get", "(", "'proto'", ")", ":", "result", ".", "append", "(", "identity_dict", "[", "'proto'", "]", "+", "'://'", ")", "if", "identity_dict",...
Dump Identity dictionary into its string representation.
[ "Dump", "Identity", "dictionary", "into", "its", "string", "representation", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/interface.py#L34-L47
9,962
romanz/trezor-agent
libagent/device/interface.py
Identity.items
def items(self): """Return a copy of identity_dict items.""" return [(k, unidecode.unidecode(v)) for k, v in self.identity_dict.items()]
python
def items(self): """Return a copy of identity_dict items.""" return [(k, unidecode.unidecode(v)) for k, v in self.identity_dict.items()]
[ "def", "items", "(", "self", ")", ":", "return", "[", "(", "k", ",", "unidecode", ".", "unidecode", "(", "v", ")", ")", "for", "k", ",", "v", "in", "self", ".", "identity_dict", ".", "items", "(", ")", "]" ]
Return a copy of identity_dict items.
[ "Return", "a", "copy", "of", "identity_dict", "items", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/interface.py#L70-L73
9,963
romanz/trezor-agent
libagent/device/interface.py
Identity.to_bytes
def to_bytes(self): """Transliterate Unicode into ASCII.""" s = identity_to_string(self.identity_dict) return unidecode.unidecode(s).encode('ascii')
python
def to_bytes(self): """Transliterate Unicode into ASCII.""" s = identity_to_string(self.identity_dict) return unidecode.unidecode(s).encode('ascii')
[ "def", "to_bytes", "(", "self", ")", ":", "s", "=", "identity_to_string", "(", "self", ".", "identity_dict", ")", "return", "unidecode", ".", "unidecode", "(", "s", ")", ".", "encode", "(", "'ascii'", ")" ]
Transliterate Unicode into ASCII.
[ "Transliterate", "Unicode", "into", "ASCII", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/interface.py#L75-L78
9,964
romanz/trezor-agent
libagent/device/interface.py
Identity.get_curve_name
def get_curve_name(self, ecdh=False): """Return correct curve name for device operations.""" if ecdh: return formats.get_ecdh_curve_name(self.curve_name) else: return self.curve_name
python
def get_curve_name(self, ecdh=False): """Return correct curve name for device operations.""" if ecdh: return formats.get_ecdh_curve_name(self.curve_name) else: return self.curve_name
[ "def", "get_curve_name", "(", "self", ",", "ecdh", "=", "False", ")", ":", "if", "ecdh", ":", "return", "formats", ".", "get_ecdh_curve_name", "(", "self", ".", "curve_name", ")", "else", ":", "return", "self", ".", "curve_name" ]
Return correct curve name for device operations.
[ "Return", "correct", "curve", "name", "for", "device", "operations", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/interface.py#L97-L102
9,965
romanz/trezor-agent
libagent/ssh/__init__.py
serve
def serve(handler, sock_path, timeout=UNIX_SOCKET_TIMEOUT): """ Start the ssh-agent server on a UNIX-domain socket. If no connection is made during the specified timeout, retry until the context is over. """ ssh_version = subprocess.check_output(['ssh', '-V'], ...
python
def serve(handler, sock_path, timeout=UNIX_SOCKET_TIMEOUT): """ Start the ssh-agent server on a UNIX-domain socket. If no connection is made during the specified timeout, retry until the context is over. """ ssh_version = subprocess.check_output(['ssh', '-V'], ...
[ "def", "serve", "(", "handler", ",", "sock_path", ",", "timeout", "=", "UNIX_SOCKET_TIMEOUT", ")", ":", "ssh_version", "=", "subprocess", ".", "check_output", "(", "[", "'ssh'", ",", "'-V'", "]", ",", "stderr", "=", "subprocess", ".", "STDOUT", ")", "log",...
Start the ssh-agent server on a UNIX-domain socket. If no connection is made during the specified timeout, retry until the context is over.
[ "Start", "the", "ssh", "-", "agent", "server", "on", "a", "UNIX", "-", "domain", "socket", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/__init__.py#L124-L150
9,966
romanz/trezor-agent
libagent/ssh/__init__.py
run_server
def run_server(conn, command, sock_path, debug, timeout): """Common code for run_agent and run_git below.""" ret = 0 try: handler = protocol.Handler(conn=conn, debug=debug) with serve(handler=handler, sock_path=sock_path, timeout=timeout) as env: if command: ...
python
def run_server(conn, command, sock_path, debug, timeout): """Common code for run_agent and run_git below.""" ret = 0 try: handler = protocol.Handler(conn=conn, debug=debug) with serve(handler=handler, sock_path=sock_path, timeout=timeout) as env: if command: ...
[ "def", "run_server", "(", "conn", ",", "command", ",", "sock_path", ",", "debug", ",", "timeout", ")", ":", "ret", "=", "0", "try", ":", "handler", "=", "protocol", ".", "Handler", "(", "conn", "=", "conn", ",", "debug", "=", "debug", ")", "with", ...
Common code for run_agent and run_git below.
[ "Common", "code", "for", "run_agent", "and", "run_git", "below", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/__init__.py#L153-L166
9,967
romanz/trezor-agent
libagent/ssh/__init__.py
handle_connection_error
def handle_connection_error(func): """Fail with non-zero exit code.""" @functools.wraps(func) def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except device.interface.NotFoundError as e: log.error('Connection error (try unplugging and replugging your de...
python
def handle_connection_error(func): """Fail with non-zero exit code.""" @functools.wraps(func) def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except device.interface.NotFoundError as e: log.error('Connection error (try unplugging and replugging your de...
[ "def", "handle_connection_error", "(", "func", ")", ":", "@", "functools", ".", "wraps", "(", "func", ")", "def", "wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "try", ":", "return", "func", "(", "*", "args", ",", "*", "*", "kwargs...
Fail with non-zero exit code.
[ "Fail", "with", "non", "-", "zero", "exit", "code", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/__init__.py#L169-L178
9,968
romanz/trezor-agent
libagent/ssh/__init__.py
parse_config
def parse_config(contents): """Parse config file into a list of Identity objects.""" for identity_str, curve_name in re.findall(r'\<(.*?)\|(.*?)\>', contents): yield device.interface.Identity(identity_str=identity_str, curve_name=curve_name)
python
def parse_config(contents): """Parse config file into a list of Identity objects.""" for identity_str, curve_name in re.findall(r'\<(.*?)\|(.*?)\>', contents): yield device.interface.Identity(identity_str=identity_str, curve_name=curve_name)
[ "def", "parse_config", "(", "contents", ")", ":", "for", "identity_str", ",", "curve_name", "in", "re", ".", "findall", "(", "r'\\<(.*?)\\|(.*?)\\>'", ",", "contents", ")", ":", "yield", "device", ".", "interface", ".", "Identity", "(", "identity_str", "=", ...
Parse config file into a list of Identity objects.
[ "Parse", "config", "file", "into", "a", "list", "of", "Identity", "objects", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/__init__.py#L181-L185
9,969
romanz/trezor-agent
libagent/ssh/__init__.py
main
def main(device_type): """Run ssh-agent using given hardware client factory.""" args = create_agent_parser(device_type=device_type).parse_args() util.setup_logging(verbosity=args.verbose, filename=args.log_file) public_keys = None filename = None if args.identity.startswith('/'): filena...
python
def main(device_type): """Run ssh-agent using given hardware client factory.""" args = create_agent_parser(device_type=device_type).parse_args() util.setup_logging(verbosity=args.verbose, filename=args.log_file) public_keys = None filename = None if args.identity.startswith('/'): filena...
[ "def", "main", "(", "device_type", ")", ":", "args", "=", "create_agent_parser", "(", "device_type", "=", "device_type", ")", ".", "parse_args", "(", ")", "util", ".", "setup_logging", "(", "verbosity", "=", "args", ".", "verbose", ",", "filename", "=", "a...
Run ssh-agent using given hardware client factory.
[ "Run", "ssh", "-", "agent", "using", "given", "hardware", "client", "factory", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/__init__.py#L255-L313
9,970
romanz/trezor-agent
libagent/ssh/__init__.py
JustInTimeConnection.parse_public_keys
def parse_public_keys(self): """Parse SSH public keys into dictionaries.""" public_keys = [formats.import_public_key(pk) for pk in self.public_keys()] for pk, identity in zip(public_keys, self.identities): pk['identity'] = identity return public_keys
python
def parse_public_keys(self): """Parse SSH public keys into dictionaries.""" public_keys = [formats.import_public_key(pk) for pk in self.public_keys()] for pk, identity in zip(public_keys, self.identities): pk['identity'] = identity return public_keys
[ "def", "parse_public_keys", "(", "self", ")", ":", "public_keys", "=", "[", "formats", ".", "import_public_key", "(", "pk", ")", "for", "pk", "in", "self", ".", "public_keys", "(", ")", "]", "for", "pk", ",", "identity", "in", "zip", "(", "public_keys", ...
Parse SSH public keys into dictionaries.
[ "Parse", "SSH", "public", "keys", "into", "dictionaries", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/__init__.py#L213-L219
9,971
romanz/trezor-agent
libagent/ssh/__init__.py
JustInTimeConnection.public_keys_as_files
def public_keys_as_files(self): """Store public keys as temporary SSH identity files.""" if not self.public_keys_tempfiles: for pk in self.public_keys(): f = tempfile.NamedTemporaryFile(prefix='trezor-ssh-pubkey-', mode='w') f.write(pk) f.flush...
python
def public_keys_as_files(self): """Store public keys as temporary SSH identity files.""" if not self.public_keys_tempfiles: for pk in self.public_keys(): f = tempfile.NamedTemporaryFile(prefix='trezor-ssh-pubkey-', mode='w') f.write(pk) f.flush...
[ "def", "public_keys_as_files", "(", "self", ")", ":", "if", "not", "self", ".", "public_keys_tempfiles", ":", "for", "pk", "in", "self", ".", "public_keys", "(", ")", ":", "f", "=", "tempfile", ".", "NamedTemporaryFile", "(", "prefix", "=", "'trezor-ssh-pubk...
Store public keys as temporary SSH identity files.
[ "Store", "public", "keys", "as", "temporary", "SSH", "identity", "files", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/__init__.py#L221-L230
9,972
romanz/trezor-agent
libagent/ssh/__init__.py
JustInTimeConnection.sign
def sign(self, blob, identity): """Sign a given blob using the specified identity on the device.""" conn = self.conn_factory() return conn.sign_ssh_challenge(blob=blob, identity=identity)
python
def sign(self, blob, identity): """Sign a given blob using the specified identity on the device.""" conn = self.conn_factory() return conn.sign_ssh_challenge(blob=blob, identity=identity)
[ "def", "sign", "(", "self", ",", "blob", ",", "identity", ")", ":", "conn", "=", "self", ".", "conn_factory", "(", ")", "return", "conn", ".", "sign_ssh_challenge", "(", "blob", "=", "blob", ",", "identity", "=", "identity", ")" ]
Sign a given blob using the specified identity on the device.
[ "Sign", "a", "given", "blob", "using", "the", "specified", "identity", "on", "the", "device", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/ssh/__init__.py#L232-L235
9,973
romanz/trezor-agent
libagent/gpg/protocol.py
packet
def packet(tag, blob): """Create small GPG packet.""" assert len(blob) < 2**32 if len(blob) < 2**8: length_type = 0 elif len(blob) < 2**16: length_type = 1 else: length_type = 2 fmt = ['>B', '>H', '>L'][length_type] leading_byte = 0x80 | (tag << 2) | (length_type) ...
python
def packet(tag, blob): """Create small GPG packet.""" assert len(blob) < 2**32 if len(blob) < 2**8: length_type = 0 elif len(blob) < 2**16: length_type = 1 else: length_type = 2 fmt = ['>B', '>H', '>L'][length_type] leading_byte = 0x80 | (tag << 2) | (length_type) ...
[ "def", "packet", "(", "tag", ",", "blob", ")", ":", "assert", "len", "(", "blob", ")", "<", "2", "**", "32", "if", "len", "(", "blob", ")", "<", "2", "**", "8", ":", "length_type", "=", "0", "elif", "len", "(", "blob", ")", "<", "2", "**", ...
Create small GPG packet.
[ "Create", "small", "GPG", "packet", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L13-L26
9,974
romanz/trezor-agent
libagent/gpg/protocol.py
subpacket
def subpacket(subpacket_type, fmt, *values): """Create GPG subpacket.""" blob = struct.pack(fmt, *values) if values else fmt return struct.pack('>B', subpacket_type) + blob
python
def subpacket(subpacket_type, fmt, *values): """Create GPG subpacket.""" blob = struct.pack(fmt, *values) if values else fmt return struct.pack('>B', subpacket_type) + blob
[ "def", "subpacket", "(", "subpacket_type", ",", "fmt", ",", "*", "values", ")", ":", "blob", "=", "struct", ".", "pack", "(", "fmt", ",", "*", "values", ")", "if", "values", "else", "fmt", "return", "struct", ".", "pack", "(", "'>B'", ",", "subpacket...
Create GPG subpacket.
[ "Create", "GPG", "subpacket", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L29-L32
9,975
romanz/trezor-agent
libagent/gpg/protocol.py
subpacket_prefix_len
def subpacket_prefix_len(item): """Prefix subpacket length according to RFC 4880 section-5.2.3.1.""" n = len(item) if n >= 8384: prefix = b'\xFF' + struct.pack('>L', n) elif n >= 192: n = n - 192 prefix = struct.pack('BB', (n // 256) + 192, n % 256) else: prefix = str...
python
def subpacket_prefix_len(item): """Prefix subpacket length according to RFC 4880 section-5.2.3.1.""" n = len(item) if n >= 8384: prefix = b'\xFF' + struct.pack('>L', n) elif n >= 192: n = n - 192 prefix = struct.pack('BB', (n // 256) + 192, n % 256) else: prefix = str...
[ "def", "subpacket_prefix_len", "(", "item", ")", ":", "n", "=", "len", "(", "item", ")", "if", "n", ">=", "8384", ":", "prefix", "=", "b'\\xFF'", "+", "struct", ".", "pack", "(", "'>L'", ",", "n", ")", "elif", "n", ">=", "192", ":", "n", "=", "...
Prefix subpacket length according to RFC 4880 section-5.2.3.1.
[ "Prefix", "subpacket", "length", "according", "to", "RFC", "4880", "section", "-", "5", ".", "2", ".", "3", ".", "1", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L55-L65
9,976
romanz/trezor-agent
libagent/gpg/protocol.py
subpackets
def subpackets(*items): """Serialize several GPG subpackets.""" prefixed = [subpacket_prefix_len(item) for item in items] return util.prefix_len('>H', b''.join(prefixed))
python
def subpackets(*items): """Serialize several GPG subpackets.""" prefixed = [subpacket_prefix_len(item) for item in items] return util.prefix_len('>H', b''.join(prefixed))
[ "def", "subpackets", "(", "*", "items", ")", ":", "prefixed", "=", "[", "subpacket_prefix_len", "(", "item", ")", "for", "item", "in", "items", "]", "return", "util", ".", "prefix_len", "(", "'>H'", ",", "b''", ".", "join", "(", "prefixed", ")", ")" ]
Serialize several GPG subpackets.
[ "Serialize", "several", "GPG", "subpackets", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L68-L71
9,977
romanz/trezor-agent
libagent/gpg/protocol.py
mpi
def mpi(value): """Serialize multipresicion integer using GPG format.""" bits = value.bit_length() data_size = (bits + 7) // 8 data_bytes = bytearray(data_size) for i in range(data_size): data_bytes[i] = value & 0xFF value = value >> 8 data_bytes.reverse() return struct.pack...
python
def mpi(value): """Serialize multipresicion integer using GPG format.""" bits = value.bit_length() data_size = (bits + 7) // 8 data_bytes = bytearray(data_size) for i in range(data_size): data_bytes[i] = value & 0xFF value = value >> 8 data_bytes.reverse() return struct.pack...
[ "def", "mpi", "(", "value", ")", ":", "bits", "=", "value", ".", "bit_length", "(", ")", "data_size", "=", "(", "bits", "+", "7", ")", "//", "8", "data_bytes", "=", "bytearray", "(", "data_size", ")", "for", "i", "in", "range", "(", "data_size", ")...
Serialize multipresicion integer using GPG format.
[ "Serialize", "multipresicion", "integer", "using", "GPG", "format", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L74-L84
9,978
romanz/trezor-agent
libagent/gpg/protocol.py
keygrip_nist256
def keygrip_nist256(vk): """Compute keygrip for NIST256 curve public keys.""" curve = vk.curve.curve gen = vk.curve.generator g = (4 << 512) | (gen.x() << 256) | gen.y() point = vk.pubkey.point q = (4 << 512) | (point.x() << 256) | point.y() return _compute_keygrip([ ['p', util.num2...
python
def keygrip_nist256(vk): """Compute keygrip for NIST256 curve public keys.""" curve = vk.curve.curve gen = vk.curve.generator g = (4 << 512) | (gen.x() << 256) | gen.y() point = vk.pubkey.point q = (4 << 512) | (point.x() << 256) | point.y() return _compute_keygrip([ ['p', util.num2...
[ "def", "keygrip_nist256", "(", "vk", ")", ":", "curve", "=", "vk", ".", "curve", ".", "curve", "gen", "=", "vk", ".", "curve", ".", "generator", "g", "=", "(", "4", "<<", "512", ")", "|", "(", "gen", ".", "x", "(", ")", "<<", "256", ")", "|",...
Compute keygrip for NIST256 curve public keys.
[ "Compute", "keygrip", "for", "NIST256", "curve", "public", "keys", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L107-L122
9,979
romanz/trezor-agent
libagent/gpg/protocol.py
keygrip_ed25519
def keygrip_ed25519(vk): """Compute keygrip for Ed25519 public keys.""" # pylint: disable=line-too-long return _compute_keygrip([ ['p', util.num2bytes(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED, size=32)], # nopep8 ['a', b'\x01'], ['b', util.num2bytes(0x2DFC9...
python
def keygrip_ed25519(vk): """Compute keygrip for Ed25519 public keys.""" # pylint: disable=line-too-long return _compute_keygrip([ ['p', util.num2bytes(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED, size=32)], # nopep8 ['a', b'\x01'], ['b', util.num2bytes(0x2DFC9...
[ "def", "keygrip_ed25519", "(", "vk", ")", ":", "# pylint: disable=line-too-long", "return", "_compute_keygrip", "(", "[", "[", "'p'", ",", "util", ".", "num2bytes", "(", "0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED", ",", "size", "=", "32", ")", ...
Compute keygrip for Ed25519 public keys.
[ "Compute", "keygrip", "for", "Ed25519", "public", "keys", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L125-L135
9,980
romanz/trezor-agent
libagent/gpg/protocol.py
keygrip_curve25519
def keygrip_curve25519(vk): """Compute keygrip for Curve25519 public keys.""" # pylint: disable=line-too-long return _compute_keygrip([ ['p', util.num2bytes(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED, size=32)], # nopep8 ['a', b'\x01\xDB\x41'], ['b', b'\x01']...
python
def keygrip_curve25519(vk): """Compute keygrip for Curve25519 public keys.""" # pylint: disable=line-too-long return _compute_keygrip([ ['p', util.num2bytes(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED, size=32)], # nopep8 ['a', b'\x01\xDB\x41'], ['b', b'\x01']...
[ "def", "keygrip_curve25519", "(", "vk", ")", ":", "# pylint: disable=line-too-long", "return", "_compute_keygrip", "(", "[", "[", "'p'", ",", "util", ".", "num2bytes", "(", "0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED", ",", "size", "=", "32", ")"...
Compute keygrip for Curve25519 public keys.
[ "Compute", "keygrip", "for", "Curve25519", "public", "keys", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L138-L148
9,981
romanz/trezor-agent
libagent/gpg/protocol.py
get_curve_name_by_oid
def get_curve_name_by_oid(oid): """Return curve name matching specified OID, or raise KeyError.""" for curve_name, info in SUPPORTED_CURVES.items(): if info['oid'] == oid: return curve_name raise KeyError('Unknown OID: {!r}'.format(oid))
python
def get_curve_name_by_oid(oid): """Return curve name matching specified OID, or raise KeyError.""" for curve_name, info in SUPPORTED_CURVES.items(): if info['oid'] == oid: return curve_name raise KeyError('Unknown OID: {!r}'.format(oid))
[ "def", "get_curve_name_by_oid", "(", "oid", ")", ":", "for", "curve_name", ",", "info", "in", "SUPPORTED_CURVES", ".", "items", "(", ")", ":", "if", "info", "[", "'oid'", "]", "==", "oid", ":", "return", "curve_name", "raise", "KeyError", "(", "'Unknown OI...
Return curve name matching specified OID, or raise KeyError.
[ "Return", "curve", "name", "matching", "specified", "OID", "or", "raise", "KeyError", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L180-L185
9,982
romanz/trezor-agent
libagent/gpg/protocol.py
make_signature
def make_signature(signer_func, data_to_sign, public_algo, hashed_subpackets, unhashed_subpackets, sig_type=0): """Create new GPG signature.""" # pylint: disable=too-many-arguments header = struct.pack('>BBBB', 4, # version sig_typ...
python
def make_signature(signer_func, data_to_sign, public_algo, hashed_subpackets, unhashed_subpackets, sig_type=0): """Create new GPG signature.""" # pylint: disable=too-many-arguments header = struct.pack('>BBBB', 4, # version sig_typ...
[ "def", "make_signature", "(", "signer_func", ",", "data_to_sign", ",", "public_algo", ",", "hashed_subpackets", ",", "unhashed_subpackets", ",", "sig_type", "=", "0", ")", ":", "# pylint: disable=too-many-arguments", "header", "=", "struct", ".", "pack", "(", "'>BBB...
Create new GPG signature.
[ "Create", "new", "GPG", "signature", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L254-L276
9,983
romanz/trezor-agent
libagent/gpg/protocol.py
PublicKey.data
def data(self): """Data for packet creation.""" header = struct.pack('>BLB', 4, # version self.created, # creation self.algo_id) # public key algorithm ID oid = util.prefix_len('>B', self.curve_i...
python
def data(self): """Data for packet creation.""" header = struct.pack('>BLB', 4, # version self.created, # creation self.algo_id) # public key algorithm ID oid = util.prefix_len('>B', self.curve_i...
[ "def", "data", "(", "self", ")", ":", "header", "=", "struct", ".", "pack", "(", "'>BLB'", ",", "4", ",", "# version", "self", ".", "created", ",", "# creation", "self", ".", "algo_id", ")", "# public key algorithm ID", "oid", "=", "util", ".", "prefix_l...
Data for packet creation.
[ "Data", "for", "packet", "creation", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/protocol.py#L209-L217
9,984
romanz/trezor-agent
libagent/gpg/encode.py
create_subkey
def create_subkey(primary_bytes, subkey, signer_func, secret_bytes=b''): """Export new subkey to GPG primary key.""" subkey_packet = protocol.packet(tag=(7 if secret_bytes else 14), blob=(subkey.data() + secret_bytes)) packets = list(decode.parse_packets(io.BytesIO(primar...
python
def create_subkey(primary_bytes, subkey, signer_func, secret_bytes=b''): """Export new subkey to GPG primary key.""" subkey_packet = protocol.packet(tag=(7 if secret_bytes else 14), blob=(subkey.data() + secret_bytes)) packets = list(decode.parse_packets(io.BytesIO(primar...
[ "def", "create_subkey", "(", "primary_bytes", ",", "subkey", ",", "signer_func", ",", "secret_bytes", "=", "b''", ")", ":", "subkey_packet", "=", "protocol", ".", "packet", "(", "tag", "=", "(", "7", "if", "secret_bytes", "else", "14", ")", ",", "blob", ...
Export new subkey to GPG primary key.
[ "Export", "new", "subkey", "to", "GPG", "primary", "key", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/encode.py#L51-L103
9,985
romanz/trezor-agent
libagent/gpg/__init__.py
verify_gpg_version
def verify_gpg_version(): """Make sure that the installed GnuPG is not too old.""" existing_gpg = keyring.gpg_version().decode('ascii') required_gpg = '>=2.1.11' msg = 'Existing GnuPG has version "{}" ({} required)'.format(existing_gpg, re...
python
def verify_gpg_version(): """Make sure that the installed GnuPG is not too old.""" existing_gpg = keyring.gpg_version().decode('ascii') required_gpg = '>=2.1.11' msg = 'Existing GnuPG has version "{}" ({} required)'.format(existing_gpg, re...
[ "def", "verify_gpg_version", "(", ")", ":", "existing_gpg", "=", "keyring", ".", "gpg_version", "(", ")", ".", "decode", "(", "'ascii'", ")", "required_gpg", "=", "'>=2.1.11'", "msg", "=", "'Existing GnuPG has version \"{}\" ({} required)'", ".", "format", "(", "e...
Make sure that the installed GnuPG is not too old.
[ "Make", "sure", "that", "the", "installed", "GnuPG", "is", "not", "too", "old", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/__init__.py#L83-L90
9,986
romanz/trezor-agent
libagent/gpg/__init__.py
check_output
def check_output(args): """Runs command and returns the output as string.""" log.debug('run: %s', args) out = subprocess.check_output(args=args).decode('utf-8') log.debug('out: %r', out) return out
python
def check_output(args): """Runs command and returns the output as string.""" log.debug('run: %s', args) out = subprocess.check_output(args=args).decode('utf-8') log.debug('out: %r', out) return out
[ "def", "check_output", "(", "args", ")", ":", "log", ".", "debug", "(", "'run: %s'", ",", "args", ")", "out", "=", "subprocess", ".", "check_output", "(", "args", "=", "args", ")", ".", "decode", "(", "'utf-8'", ")", "log", ".", "debug", "(", "'out: ...
Runs command and returns the output as string.
[ "Runs", "command", "and", "returns", "the", "output", "as", "string", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/__init__.py#L93-L98
9,987
romanz/trezor-agent
libagent/gpg/__init__.py
check_call
def check_call(args, stdin=None, env=None): """Runs command and verifies its success.""" log.debug('run: %s%s', args, ' {}'.format(env) if env else '') subprocess.check_call(args=args, stdin=stdin, env=env)
python
def check_call(args, stdin=None, env=None): """Runs command and verifies its success.""" log.debug('run: %s%s', args, ' {}'.format(env) if env else '') subprocess.check_call(args=args, stdin=stdin, env=env)
[ "def", "check_call", "(", "args", ",", "stdin", "=", "None", ",", "env", "=", "None", ")", ":", "log", ".", "debug", "(", "'run: %s%s'", ",", "args", ",", "' {}'", ".", "format", "(", "env", ")", "if", "env", "else", "''", ")", "subprocess", ".", ...
Runs command and verifies its success.
[ "Runs", "command", "and", "verifies", "its", "success", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/__init__.py#L101-L104
9,988
romanz/trezor-agent
libagent/gpg/__init__.py
write_file
def write_file(path, data): """Writes data to specified path.""" with open(path, 'w') as f: log.debug('setting %s contents:\n%s', path, data) f.write(data) return f
python
def write_file(path, data): """Writes data to specified path.""" with open(path, 'w') as f: log.debug('setting %s contents:\n%s', path, data) f.write(data) return f
[ "def", "write_file", "(", "path", ",", "data", ")", ":", "with", "open", "(", "path", ",", "'w'", ")", "as", "f", ":", "log", ".", "debug", "(", "'setting %s contents:\\n%s'", ",", "path", ",", "data", ")", "f", ".", "write", "(", "data", ")", "ret...
Writes data to specified path.
[ "Writes", "data", "to", "specified", "path", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/__init__.py#L107-L112
9,989
romanz/trezor-agent
libagent/gpg/__init__.py
run_agent
def run_agent(device_type): """Run a simple GPG-agent server.""" p = argparse.ArgumentParser() p.add_argument('--homedir', default=os.environ.get('GNUPGHOME')) p.add_argument('-v', '--verbose', default=0, action='count') p.add_argument('--server', default=False, action='store_true', ...
python
def run_agent(device_type): """Run a simple GPG-agent server.""" p = argparse.ArgumentParser() p.add_argument('--homedir', default=os.environ.get('GNUPGHOME')) p.add_argument('-v', '--verbose', default=0, action='count') p.add_argument('--server', default=False, action='store_true', ...
[ "def", "run_agent", "(", "device_type", ")", ":", "p", "=", "argparse", ".", "ArgumentParser", "(", ")", "p", ".", "add_argument", "(", "'--homedir'", ",", "default", "=", "os", ".", "environ", ".", "get", "(", "'GNUPGHOME'", ")", ")", "p", ".", "add_a...
Run a simple GPG-agent server.
[ "Run", "a", "simple", "GPG", "-", "agent", "server", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/__init__.py#L222-L276
9,990
romanz/trezor-agent
libagent/device/trezor_defs.py
find_device
def find_device(): """Selects a transport based on `TREZOR_PATH` environment variable. If unset, picks first connected device. """ try: return get_transport(os.environ.get("TREZOR_PATH")) except Exception as e: # pylint: disable=broad-except log.debug("Failed to find a Trezor devic...
python
def find_device(): """Selects a transport based on `TREZOR_PATH` environment variable. If unset, picks first connected device. """ try: return get_transport(os.environ.get("TREZOR_PATH")) except Exception as e: # pylint: disable=broad-except log.debug("Failed to find a Trezor devic...
[ "def", "find_device", "(", ")", ":", "try", ":", "return", "get_transport", "(", "os", ".", "environ", ".", "get", "(", "\"TREZOR_PATH\"", ")", ")", "except", "Exception", "as", "e", ":", "# pylint: disable=broad-except", "log", ".", "debug", "(", "\"Failed ...
Selects a transport based on `TREZOR_PATH` environment variable. If unset, picks first connected device.
[ "Selects", "a", "transport", "based", "on", "TREZOR_PATH", "environment", "variable", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/trezor_defs.py#L22-L30
9,991
romanz/trezor-agent
libagent/device/ledger.py
_convert_public_key
def _convert_public_key(ecdsa_curve_name, result): """Convert Ledger reply into PublicKey object.""" if ecdsa_curve_name == 'nist256p1': if (result[64] & 1) != 0: result = bytearray([0x03]) + result[1:33] else: result = bytearray([0x02]) + result[1:33] else: r...
python
def _convert_public_key(ecdsa_curve_name, result): """Convert Ledger reply into PublicKey object.""" if ecdsa_curve_name == 'nist256p1': if (result[64] & 1) != 0: result = bytearray([0x03]) + result[1:33] else: result = bytearray([0x02]) + result[1:33] else: r...
[ "def", "_convert_public_key", "(", "ecdsa_curve_name", ",", "result", ")", ":", "if", "ecdsa_curve_name", "==", "'nist256p1'", ":", "if", "(", "result", "[", "64", "]", "&", "1", ")", "!=", "0", ":", "result", "=", "bytearray", "(", "[", "0x03", "]", "...
Convert Ledger reply into PublicKey object.
[ "Convert", "Ledger", "reply", "into", "PublicKey", "object", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/ledger.py#L19-L33
9,992
romanz/trezor-agent
libagent/device/ledger.py
LedgerNanoS.connect
def connect(self): """Enumerate and connect to the first USB HID interface.""" try: return comm.getDongle() except comm.CommException as e: raise interface.NotFoundError( '{} not connected: "{}"'.format(self, e))
python
def connect(self): """Enumerate and connect to the first USB HID interface.""" try: return comm.getDongle() except comm.CommException as e: raise interface.NotFoundError( '{} not connected: "{}"'.format(self, e))
[ "def", "connect", "(", "self", ")", ":", "try", ":", "return", "comm", ".", "getDongle", "(", ")", "except", "comm", ".", "CommException", "as", "e", ":", "raise", "interface", ".", "NotFoundError", "(", "'{} not connected: \"{}\"'", ".", "format", "(", "s...
Enumerate and connect to the first USB HID interface.
[ "Enumerate", "and", "connect", "to", "the", "first", "USB", "HID", "interface", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/ledger.py#L44-L50
9,993
romanz/trezor-agent
libagent/device/ledger.py
LedgerNanoS.pubkey
def pubkey(self, identity, ecdh=False): """Get PublicKey object for specified BIP32 address and elliptic curve.""" curve_name = identity.get_curve_name(ecdh) path = _expand_path(identity.get_bip32_address(ecdh)) if curve_name == 'nist256p1': p2 = '01' else: ...
python
def pubkey(self, identity, ecdh=False): """Get PublicKey object for specified BIP32 address and elliptic curve.""" curve_name = identity.get_curve_name(ecdh) path = _expand_path(identity.get_bip32_address(ecdh)) if curve_name == 'nist256p1': p2 = '01' else: ...
[ "def", "pubkey", "(", "self", ",", "identity", ",", "ecdh", "=", "False", ")", ":", "curve_name", "=", "identity", ".", "get_curve_name", "(", "ecdh", ")", "path", "=", "_expand_path", "(", "identity", ".", "get_bip32_address", "(", "ecdh", ")", ")", "if...
Get PublicKey object for specified BIP32 address and elliptic curve.
[ "Get", "PublicKey", "object", "for", "specified", "BIP32", "address", "and", "elliptic", "curve", "." ]
513b1259c4d7aca5f88cd958edc11828d0712f1b
https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/device/ledger.py#L52-L67
9,994
inonit/drf-haystack
ez_setup.py
download_setuptools
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, delay=15): """Download distribute from a specified location and return its filename `version` should be a valid distribute version number that is available as an egg for download under the ...
python
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, delay=15): """Download distribute from a specified location and return its filename `version` should be a valid distribute version number that is available as an egg for download under the ...
[ "def", "download_setuptools", "(", "version", "=", "DEFAULT_VERSION", ",", "download_base", "=", "DEFAULT_URL", ",", "to_dir", "=", "os", ".", "curdir", ",", "delay", "=", "15", ")", ":", "# making sure we use the absolute path", "to_dir", "=", "os", ".", "path"...
Download distribute from a specified location and return its filename `version` should be a valid distribute version number that is available as an egg for download under the `download_base` URL (which should end with a '/'). `to_dir` is the directory where the egg will be downloaded. `delay` is the nu...
[ "Download", "distribute", "from", "a", "specified", "location", "and", "return", "its", "filename" ]
ceabd0f6318f129758341ab08292a20205d6f4cd
https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/ez_setup.py#L170-L204
9,995
inonit/drf-haystack
drf_haystack/query.py
BaseQueryBuilder.tokenize
def tokenize(stream, separator): """ Tokenize and yield query parameter values. :param stream: Input value :param separator: Character to use to separate the tokens. :return: """ for value in stream: for token in value.split(separator): ...
python
def tokenize(stream, separator): """ Tokenize and yield query parameter values. :param stream: Input value :param separator: Character to use to separate the tokens. :return: """ for value in stream: for token in value.split(separator): ...
[ "def", "tokenize", "(", "stream", ",", "separator", ")", ":", "for", "value", "in", "stream", ":", "for", "token", "in", "value", ".", "split", "(", "separator", ")", ":", "if", "token", ":", "yield", "token", ".", "strip", "(", ")" ]
Tokenize and yield query parameter values. :param stream: Input value :param separator: Character to use to separate the tokens. :return:
[ "Tokenize", "and", "yield", "query", "parameter", "values", "." ]
ceabd0f6318f129758341ab08292a20205d6f4cd
https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/query.py#L34-L45
9,996
inonit/drf-haystack
drf_haystack/query.py
FilterQueryBuilder.build_query
def build_query(self, **filters): """ Creates a single SQ filter from querystring parameters that correspond to the SearchIndex fields that have been "registered" in `view.fields`. Default behavior is to `OR` terms for the same parameters, and `AND` between parameters. Any query...
python
def build_query(self, **filters): """ Creates a single SQ filter from querystring parameters that correspond to the SearchIndex fields that have been "registered" in `view.fields`. Default behavior is to `OR` terms for the same parameters, and `AND` between parameters. Any query...
[ "def", "build_query", "(", "self", ",", "*", "*", "filters", ")", ":", "applicable_filters", "=", "[", "]", "applicable_exclusions", "=", "[", "]", "for", "param", ",", "value", "in", "filters", ".", "items", "(", ")", ":", "excluding_term", "=", "False"...
Creates a single SQ filter from querystring parameters that correspond to the SearchIndex fields that have been "registered" in `view.fields`. Default behavior is to `OR` terms for the same parameters, and `AND` between parameters. Any querystring parameters that are not registered in `view.fie...
[ "Creates", "a", "single", "SQ", "filter", "from", "querystring", "parameters", "that", "correspond", "to", "the", "SearchIndex", "fields", "that", "have", "been", "registered", "in", "view", ".", "fields", "." ]
ceabd0f6318f129758341ab08292a20205d6f4cd
https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/query.py#L89-L151
9,997
inonit/drf-haystack
drf_haystack/query.py
FacetQueryBuilder.build_query
def build_query(self, **filters): """ Creates a dict of dictionaries suitable for passing to the SearchQuerySet `facet`, `date_facet` or `query_facet` method. All key word arguments should be wrapped in a list. :param view: API View :param dict[str, list[str]] filters: is an ex...
python
def build_query(self, **filters): """ Creates a dict of dictionaries suitable for passing to the SearchQuerySet `facet`, `date_facet` or `query_facet` method. All key word arguments should be wrapped in a list. :param view: API View :param dict[str, list[str]] filters: is an ex...
[ "def", "build_query", "(", "self", ",", "*", "*", "filters", ")", ":", "field_facets", "=", "{", "}", "date_facets", "=", "{", "}", "query_facets", "=", "{", "}", "facet_serializer_cls", "=", "self", ".", "view", ".", "get_facet_serializer_class", "(", ")"...
Creates a dict of dictionaries suitable for passing to the SearchQuerySet `facet`, `date_facet` or `query_facet` method. All key word arguments should be wrapped in a list. :param view: API View :param dict[str, list[str]] filters: is an expanded QueryDict or a mapping of keys to a lis...
[ "Creates", "a", "dict", "of", "dictionaries", "suitable", "for", "passing", "to", "the", "SearchQuerySet", "facet", "date_facet", "or", "query_facet", "method", ".", "All", "key", "word", "arguments", "should", "be", "wrapped", "in", "a", "list", "." ]
ceabd0f6318f129758341ab08292a20205d6f4cd
https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/query.py#L159-L210
9,998
inonit/drf-haystack
drf_haystack/query.py
FacetQueryBuilder.parse_field_options
def parse_field_options(self, *options): """ Parse the field options query string and return it as a dictionary. """ defaults = {} for option in options: if isinstance(option, six.text_type): tokens = [token.strip() for token in option.split(self.view....
python
def parse_field_options(self, *options): """ Parse the field options query string and return it as a dictionary. """ defaults = {} for option in options: if isinstance(option, six.text_type): tokens = [token.strip() for token in option.split(self.view....
[ "def", "parse_field_options", "(", "self", ",", "*", "options", ")", ":", "defaults", "=", "{", "}", "for", "option", "in", "options", ":", "if", "isinstance", "(", "option", ",", "six", ".", "text_type", ")", ":", "tokens", "=", "[", "token", ".", "...
Parse the field options query string and return it as a dictionary.
[ "Parse", "the", "field", "options", "query", "string", "and", "return", "it", "as", "a", "dictionary", "." ]
ceabd0f6318f129758341ab08292a20205d6f4cd
https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/query.py#L212-L239
9,999
inonit/drf-haystack
drf_haystack/query.py
SpatialQueryBuilder.build_query
def build_query(self, **filters): """ Build queries for geo spatial filtering. Expected query parameters are: - a `unit=value` parameter where the unit is a valid UNIT in the `django.contrib.gis.measure.Distance` class. - `from` which must be a comma separated latit...
python
def build_query(self, **filters): """ Build queries for geo spatial filtering. Expected query parameters are: - a `unit=value` parameter where the unit is a valid UNIT in the `django.contrib.gis.measure.Distance` class. - `from` which must be a comma separated latit...
[ "def", "build_query", "(", "self", ",", "*", "*", "filters", ")", ":", "applicable_filters", "=", "None", "filters", "=", "dict", "(", "(", "k", ",", "filters", "[", "k", "]", ")", "for", "k", "in", "chain", "(", "self", ".", "D", ".", "UNITS", "...
Build queries for geo spatial filtering. Expected query parameters are: - a `unit=value` parameter where the unit is a valid UNIT in the `django.contrib.gis.measure.Distance` class. - `from` which must be a comma separated latitude and longitude. Example query: ...
[ "Build", "queries", "for", "geo", "spatial", "filtering", "." ]
ceabd0f6318f129758341ab08292a20205d6f4cd
https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/query.py#L266-L318