diff options
author | Determinant <[email protected]> | 2020-08-16 02:31:31 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2020-08-16 02:31:31 -0400 |
commit | 05da4603fb8155f89fc24dcebf880938a0394e85 (patch) | |
tree | 941ef65de10a94485cef3b98a92298d69524aa2a /freezed_deps/ecdsa/_compat.py | |
parent | 17390b9905330a05ff68998f690d7d7a1bcf29d8 (diff) |
freeze the dependencies
Diffstat (limited to 'freezed_deps/ecdsa/_compat.py')
-rw-r--r-- | freezed_deps/ecdsa/_compat.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/freezed_deps/ecdsa/_compat.py b/freezed_deps/ecdsa/_compat.py new file mode 100644 index 0000000..965d8c4 --- /dev/null +++ b/freezed_deps/ecdsa/_compat.py @@ -0,0 +1,39 @@ +""" +Common functions for providing cross-python version compatibility. +""" +import sys +from six import integer_types + + +def str_idx_as_int(string, index): + """Take index'th byte from string, return as integer""" + val = string[index] + if isinstance(val, integer_types): + return val + return ord(val) + + +if sys.version_info < (3, 0): + def normalise_bytes(buffer_object): + """Cast the input into array of bytes.""" + # flake8 runs on py3 where `buffer` indeed doesn't exist... + return buffer(buffer_object) # noqa: F821 + + def hmac_compat(ret): + return ret + +else: + if sys.version_info < (3, 4): + # on python 3.3 hmac.hmac.update() accepts only bytes, on newer + # versions it does accept memoryview() also + def hmac_compat(data): + if not isinstance(data, bytes): + return bytes(data) + return data + else: + def hmac_compat(data): + return data + + def normalise_bytes(buffer_object): + """Cast the input into array of bytes.""" + return memoryview(buffer_object).cast('B') |