diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-10-31 20:47:23 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-11-26 18:56:27 +0100 |
commit | 103f71bb4e06132e70eb26fc2f1c5ca560068107 (patch) | |
tree | a0e04464ec93dede63c40d407c343630974a0bf4 /unittest/misc.py | |
parent | 266b57dfe7b36799243816b7af22f3dd69b0d197 (diff) | |
download | libnitrokey-103f71bb4e06132e70eb26fc2f1c5ca560068107.tar.gz libnitrokey-103f71bb4e06132e70eb26fc2f1c5ca560068107.tar.bz2 |
Tests reorganization (Python)
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'unittest/misc.py')
-rw-r--r-- | unittest/misc.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/unittest/misc.py b/unittest/misc.py new file mode 100644 index 0000000..b45436d --- /dev/null +++ b/unittest/misc.py @@ -0,0 +1,40 @@ +import cffi + +ffi = cffi.FFI() +gs = ffi.string + + +def to_hex(s): + return "".join("{:02x}".format(ord(c)) for c in s) + + +def wait(t): + import time + msg = 'Waiting for %d seconds' % t + print(msg.center(40, '=')) + time.sleep(t) + + +def cast_pointer_to_tuple(obj, typen, len): + # usage: + # config = cast_pointer_to_tuple(config_raw_data, 'uint8_t', 5) + return tuple(ffi.cast("%s [%d]" % (typen, len), obj)[0:len]) + +def get_firmware_version_from_status(C): + status = gs(C.NK_status()) + status = [s if 'firmware_version' in s else '' for s in status.split('\n')] + firmware = status[0].split(':')[1] + return firmware + + +def is_pro_rtm_07(C): + firmware = get_firmware_version_from_status(C) + return '07 00' in firmware + + +def is_storage(C): + """ + exact firmware storage is sent by other function + """ + firmware = get_firmware_version_from_status(C) + return '01 00' in firmware
\ No newline at end of file |