本文整理汇总了Python中pyhsm.cmd.YHSM_Cmd.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python YHSM_Cmd.__init__方法的具体用法?Python YHSM_Cmd.__init__怎么用?Python YHSM_Cmd.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyhsm.cmd.YHSM_Cmd
的用法示例。
在下文中一共展示了YHSM_Cmd.__init__方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pyhsm.cmd import YHSM_Cmd [as 别名]
# 或者: from pyhsm.cmd.YHSM_Cmd import __init__ [as 别名]
def __init__(self, stick, key=''):
payload = pyhsm.util.input_validate_str(key, 'key', max_len = pyhsm.defines.YSM_MAX_KEY_SIZE)
# typedef struct {
# uint8_t key[YSM_MAX_KEY_SIZE]; // Key store decryption key
# } YSM_KEY_STORE_DECRYPT_REQ;
packed = payload.ljust(pyhsm.defines.YSM_MAX_KEY_SIZE, chr(0x0))
YHSM_Cmd.__init__(self, stick, pyhsm.defines.YSM_KEY_STORE_DECRYPT, packed)
示例2: __init__
# 需要导入模块: from pyhsm.cmd import YHSM_Cmd [as 别名]
# 或者: from pyhsm.cmd.YHSM_Cmd import __init__ [as 别名]
def __init__(self, stick, public_id, key_handle, aead, nonce = None):
self.key_handle = pyhsm.util.input_validate_key_handle(key_handle)
self.public_id = pyhsm.util.input_validate_nonce(public_id, pad = True)
aead = pyhsm.util.input_validate_aead(aead, expected_len = pyhsm.defines.YSM_YUBIKEY_AEAD_SIZE)
if nonce is None:
# typedef struct {
# uint8_t publicId[YSM_PUBLIC_ID_SIZE]; // Public id (nonce)
# uint32_t keyHandle; // Key handle
# uint8_t aead[YSM_YUBIKEY_AEAD_SIZE]; // AEAD block
# } YSM_DB_YUBIKEY_AEAD_STORE_REQ;
fmt = "< %is I %is" % (pyhsm.defines.YSM_PUBLIC_ID_SIZE, \
pyhsm.defines.YSM_YUBIKEY_AEAD_SIZE)
packed = struct.pack(fmt, self.public_id, self.key_handle, aead)
YHSM_Cmd.__init__(self, stick, pyhsm.defines.YSM_DB_YUBIKEY_AEAD_STORE, packed)
else:
nonce = pyhsm.util.input_validate_nonce(nonce)
# typedef struct {
# uint8_t publicId[YSM_PUBLIC_ID_SIZE]; // Public id
# uint32_t keyHandle; // Key handle
# uint8_t aead[YSM_YUBIKEY_AEAD_SIZE]; // AEAD block
# uint8_t nonce[YSM_AEAD_NONCE_SIZE]; // Nonce
# } YSM_DB_YUBIKEY_AEAD_STORE2_REQ;
fmt = "< %is I %is %is" % (pyhsm.defines.YSM_PUBLIC_ID_SIZE, \
pyhsm.defines.YSM_YUBIKEY_AEAD_SIZE, \
pyhsm.defines.YSM_AEAD_NONCE_SIZE)
packed = struct.pack(fmt, self.public_id, self.key_handle, aead, nonce)
YHSM_Cmd.__init__(self, stick, pyhsm.defines.YSM_DB_YUBIKEY_AEAD_STORE2, packed)
示例3: __init__
# 需要导入模块: from pyhsm.cmd import YHSM_Cmd [as 别名]
# 或者: from pyhsm.cmd.YHSM_Cmd import __init__ [as 别名]
def __init__(self, stick):
YHSM_Cmd.__init__(self, stick, pyhsm.defines.YSM_SYSTEM_INFO_QUERY)
self.version_major = 0
self.version_minor = 0
self.version_build = 0
self.protocol_ver = 0
self.system_uid = None
示例4: __init__
# 需要导入模块: from pyhsm.cmd import YHSM_Cmd [as 别名]
# 或者: from pyhsm.cmd.YHSM_Cmd import __init__ [as 别名]
def __init__(self, stick, payload=''):
#define YHSM_MONITOR_EXIT 0x7f // Exit to monitor (no response sent)
#define YHSM_MONITOR_EXIT_MAGIC 0xbaadbeef
#typedef struct {
# uint32_t magic; // Magic number for trigger
# uint32_t magicInv; // 1st complement of magic
#} YHSM_MONITOR_EXIT_REQ;
packed = struct.pack('<II', 0xbaadbeef, 0xffffffff - 0xbaadbeef)
YHSM_Cmd.__init__(self, stick, pyhsm.defines.YSM_MONITOR_EXIT, packed)
示例5: __init__
# 需要导入模块: from pyhsm.cmd import YHSM_Cmd [as 别名]
# 或者: from pyhsm.cmd.YHSM_Cmd import __init__ [as 别名]
def __init__(self, stick, num_bytes, offset = 0):
self.offset = offset
self.num_bytes = num_bytes
# typedef struct {
# uint8_t offs; // Offset in buffer. Zero flushes/resets buffer first
# uint8_t numBytes; // Number of bytes to randomize
# } YSM_BUFFER_RANDOM_LOAD_REQ;
fmt = "B B"
packed = struct.pack(fmt, self.offset, self.num_bytes)
YHSM_Cmd.__init__(self, stick, pyhsm.defines.YSM_BUFFER_RANDOM_LOAD, packed)
示例6: __init__
# 需要导入模块: from pyhsm.cmd import YHSM_Cmd [as 别名]
# 或者: from pyhsm.cmd.YHSM_Cmd import __init__ [as 别名]
def __init__(self, stick, key_handle, data, flags = None, final = True, to_buffer = False):
data = pyhsm.util.input_validate_str(data, 'data', max_len = pyhsm.defines.YSM_MAX_PKT_SIZE - 6)
self.key_handle = pyhsm.util.input_validate_key_handle(key_handle)
if flags != None:
flags = pyhsm.util.input_validate_int(flags, 'flags', max_value=0xff)
else:
flags = pyhsm.defines.YSM_HMAC_SHA1_RESET
if final:
flags |= pyhsm.defines.YSM_HMAC_SHA1_FINAL
if to_buffer:
flags |= pyhsm.defines.YSM_HMAC_SHA1_TO_BUFFER
self.final = final
self.flags = flags
packed = _raw_pack(self.key_handle, self.flags, data)
YHSM_Cmd.__init__(self, stick, pyhsm.defines.YSM_HMAC_SHA1_GENERATE, packed)
示例7: __init__
# 需要导入模块: from pyhsm.cmd import YHSM_Cmd [as 别名]
# 或者: from pyhsm.cmd.YHSM_Cmd import __init__ [as 别名]
def __init__(self, stick, nonce, key_handle, aead, cleartext):
aead = pyhsm.util.input_validate_aead(aead)
expected_ct_len = len(aead) - pyhsm.defines.YSM_AEAD_MAC_SIZE
cleartext = pyhsm.util.input_validate_str(cleartext, 'cleartext', exact_len = expected_ct_len)
self.nonce = pyhsm.util.input_validate_nonce(nonce, pad = True)
self.key_handle = pyhsm.util.input_validate_key_handle(key_handle)
data = cleartext + aead
if len(data) > pyhsm.defines.YSM_MAX_PKT_SIZE - 10:
raise pyhsm.exception.YHSM_InputTooLong(
'cleartext+aead', pyhsm.defines.YSM_MAX_PKT_SIZE - 10, len(data))
# typedef struct {
# uint8_t nonce[YSM_AEAD_NONCE_SIZE]; // Nonce (publicId for Yubikey AEADs)
# uint32_t keyHandle; // Key handle
# uint8_t numBytes; // Number of data bytes (cleartext + aead)
# uint8_t data[YSM_MAX_PKT_SIZE - 0x10]; // Data (cleartext + aead). Empty cleartext validates aead only
# } YSM_AEAD_DECRYPT_CMP_REQ;
fmt = "< %is I B %is" % (pyhsm.defines.YSM_AEAD_NONCE_SIZE, len(data))
packed = struct.pack(fmt, self.nonce, key_handle, len(data), data)
YHSM_Cmd.__init__(self, stick, pyhsm.defines.YSM_AEAD_DECRYPT_CMP, packed)
示例8: __init__
# 需要导入模块: from pyhsm.cmd import YHSM_Cmd [as 别名]
# 或者: from pyhsm.cmd.YHSM_Cmd import __init__ [as 别名]
def __init__(self, stick, command, payload):
YHSM_Cmd.__init__(self, stick, command, payload)