<s> import sys <EOL> import unittest <EOL> import pyhsm <EOL> import test_common <EOL> class TestSoftHSM ( test_common . YHSM_TestCase ) : <EOL> def setUp ( self ) : <EOL> test_common . YHSM_TestCase . setUp ( self ) <EOL> self . nonce = "<STR_LIT>" . decode ( '<STR_LIT>' ) <EOL> self . key = "<STR_LIT:A>" * <NUM_LIT:16> <EOL> def test_aes_CCM_encrypt_decrypt ( self ) : <EOL> """<STR_LIT>""" <EOL> key = chr ( <NUM_LIT> ) * <NUM_LIT:16> <EOL> key_handle = <NUM_LIT:1> <EOL> plaintext = "<STR_LIT:foo>" . ljust ( <NUM_LIT:16> , chr ( <NUM_LIT> ) ) <EOL> ct = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , plaintext , decrypt = False ) <EOL> pt = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , ct , decrypt = True ) <EOL> self . assertEquals ( plaintext , pt ) <EOL> def test_aes_CCM_wrong_key ( self ) : <EOL> """<STR_LIT>""" <EOL> key = chr ( <NUM_LIT> ) * <NUM_LIT:16> <EOL> key_handle = <NUM_LIT:1> <EOL> plaintext = "<STR_LIT:foo>" . ljust ( <NUM_LIT:16> , chr ( <NUM_LIT> ) ) <EOL> ct = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , plaintext , decrypt = False ) <EOL> key = chr ( <NUM_LIT> ) * <NUM_LIT:16> <EOL> self . assertRaises ( pyhsm . exception . YHSM_Error , pyhsm . soft_hsm . aesCCM , <EOL> key , key_handle , self . nonce , ct , decrypt = True ) <EOL> def test_aes_CCM_wrong_key_handle ( self ) : <EOL> """<STR_LIT>""" <EOL> key = chr ( <NUM_LIT> ) * <NUM_LIT:16> <EOL> key_handle = <NUM_LIT:1> <EOL> plaintext = "<STR_LIT:foo>" . ljust ( <NUM_LIT:16> , chr ( <NUM_LIT> ) ) <EOL> ct = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , plaintext , decrypt = False ) <EOL> key_handle = <NUM_LIT:2> <EOL> self . assertRaises ( pyhsm . exception . YHSM_Error , pyhsm . soft_hsm . aesCCM , <EOL> key , key_handle , self . nonce , ct , decrypt = True ) <EOL> def test_soft_simple_aead_generation ( self ) : <EOL> """<STR_LIT>""" <EOL> key_handle = <NUM_LIT> <EOL> plaintext = '<STR_LIT:foo>' . ljust ( <NUM_LIT:16> , chr ( <NUM_LIT> ) ) <EOL> key = str ( "<STR_LIT>" * <NUM_LIT:16> ) . decode ( '<STR_LIT>' ) <EOL> ct = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , plaintext , decrypt = False ) <EOL> aead = self . hsm . generate_aead_simple ( self . nonce , key_handle , plaintext ) <EOL> ct = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , plaintext , decrypt = False ) <EOL> self . assertEquals ( aead . data , ct ) <EOL> pt = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , ct , decrypt = True ) <EOL> self . assertEquals ( plaintext , pt ) <EOL> def test_soft_generate_long_aead ( self ) : <EOL> """<STR_LIT>""" <EOL> key_handle = <NUM_LIT> <EOL> plaintext = '<STR_LIT:A>' * <NUM_LIT:64> <EOL> key = str ( "<STR_LIT>" * <NUM_LIT:16> ) . decode ( '<STR_LIT>' ) <EOL> ct = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , plaintext , decrypt = False ) <EOL> aead = self . hsm . generate_aead_simple ( self . nonce , key_handle , plaintext ) <EOL> self . assertEquals ( aead . data , ct ) <EOL> pt = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , ct , decrypt = True ) <EOL> self . assertEquals ( plaintext , pt ) <EOL> def test_soft_generate_yubikey_secrets_aead ( self ) : <EOL> """<STR_LIT>""" <EOL> key_handle = <NUM_LIT> <EOL> plaintext = '<STR_LIT:A>' * <NUM_LIT> <EOL> key = str ( "<STR_LIT>" * <NUM_LIT:16> ) . decode ( '<STR_LIT>' ) <EOL> ct = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , plaintext , decrypt = False ) <EOL> aead = self . hsm . generate_aead_simple ( self . nonce , key_handle , plaintext ) <EOL> self . assertEquals ( aead . data , ct ) <EOL> pt = pyhsm . soft_hsm . aesCCM ( key , key_handle , self . nonce , ct , decrypt = True ) <EOL> self . assertEquals ( plaintext , pt ) </s>
