diff options
author | Jack Lloyd <[email protected]> | 2018-08-11 17:55:50 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-08-11 17:55:50 -0400 |
commit | cb05f9c9938434c0c56122addd94015e7df38b19 (patch) | |
tree | 11df42809c02f6a6bf3d0ae6f7f2fb358867474a | |
parent | cb3b4483d7784a6c593e13c91fa2325b2c31208b (diff) |
In Python expose new name getters
-rwxr-xr-x | src/python/botan2.py | 24 | ||||
-rw-r--r-- | src/scripts/test_python.py | 14 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/python/botan2.py b/src/python/botan2.py index 021ac8a61..617efa887 100755 --- a/src/python/botan2.py +++ b/src/python/botan2.py @@ -110,6 +110,9 @@ botan.botan_hash_init.errcheck = errcheck_for('botan_hash_init') botan.botan_hash_destroy.argtypes = [c_void_p] botan.botan_hash_destroy.errcheck = errcheck_for('botan_hash_destroy') +botan.botan_hash_name.argtypes = [c_void_p, POINTER(c_char), POINTER(c_size_t)] +botan.botan_hash_name.errcheck = errcheck_for('botan_hash_name') + botan.botan_hash_clear.argtypes = [c_void_p] botan.botan_hash_clear.errcheck = errcheck_for('botan_hash_clear') @@ -129,6 +132,9 @@ botan.botan_mac_init.errcheck = errcheck_for('botan_mac_init') botan.botan_mac_destroy.argtypes = [c_void_p] botan.botan_mac_destroy.errcheck = errcheck_for('botan_mac_destroy') +botan.botan_mac_name.argtypes = [c_void_p, POINTER(c_char), POINTER(c_size_t)] +botan.botan_mac_name.errcheck = errcheck_for('botan_mac_name') + botan.botan_mac_clear.argtypes = [c_void_p] botan.botan_mac_clear.errcheck = errcheck_for('botan_mac_clear') @@ -151,6 +157,9 @@ botan.botan_cipher_init.errcheck = errcheck_for('botan_cipher_init') botan.botan_cipher_destroy.argtypes = [c_void_p] botan.botan_cipher_destroy.errcheck = errcheck_for('botan_cipher_destroy') +botan.botan_cipher_name.argtypes = [c_void_p, POINTER(c_char), POINTER(c_size_t)] +botan.botan_cipher_name.errcheck = errcheck_for('botan_cipher_name') + botan.botan_cipher_get_default_nonce_length.argtypes = [c_void_p, POINTER(c_size_t)] botan.botan_cipher_get_default_nonce_length.errcheck = errcheck_for('botan_cipher_get_default_nonce_length') @@ -226,6 +235,9 @@ botan.botan_pubkey_fingerprint.errcheck = errcheck_for('botan_pubkey_fingerprint botan.botan_privkey_create.argtypes = [c_void_p, c_char_p, c_char_p, c_void_p] botan.botan_privkey_create.errcheck = errcheck_for('botan_privkey_create') +botan.botan_privkey_algo_name.argtypes = [c_void_p, POINTER(c_char), POINTER(c_size_t)] +botan.botan_privkey_algo_name.errcheck = errcheck_for('botan_privkey_algo_name') + botan.botan_privkey_export_pubkey.argtypes = [c_void_p, c_void_p] botan.botan_privkey_export_pubkey.errcheck = errcheck_for('botan_privkey_export_pubkey') @@ -454,6 +466,9 @@ class hash_function(object): # pylint: disable=invalid-name def __del__(self): botan.botan_hash_destroy(self.hash) + def algo_name(self): + return _call_fn_returning_string(32, lambda b, bl: botan.botan_hash_name(self.hash, b, bl)) + def clear(self): botan.botan_hash_clear(self.hash) @@ -485,6 +500,9 @@ class message_authentication_code(object): # pylint: disable=invalid-name def clear(self): botan.botan_mac_clear(self.mac) + def algo_name(self): + return _call_fn_returning_string(32, lambda b, bl: botan.botan_mac_name(self.mac, b, bl)) + def output_length(self): l = c_size_t(0) botan.botan_mac_output_length(self.mac, byref(l)) @@ -510,6 +528,9 @@ class cipher(object): # pylint: disable=invalid-name def __del__(self): botan.botan_cipher_destroy(self.cipher) + def algo_name(self): + return _call_fn_returning_string(32, lambda b, bl: botan.botan_cipher_name(self.cipher, b, bl)) + def default_nonce_length(self): l = c_size_t(0) botan.botan_cipher_get_default_nonce_length(self.cipher, byref(l)) @@ -694,6 +715,9 @@ class private_key(object): # pylint: disable=invalid-name def __del__(self): botan.botan_privkey_destroy(self.privkey) + def algo_name(self): + return _call_fn_returning_string(32, lambda b, bl: botan.botan_privkey_algo_name(self.privkey, b, bl)) + def get_public_key(self): pub = c_void_p(0) diff --git a/src/scripts/test_python.py b/src/scripts/test_python.py index 32e57bc0a..34233f6f9 100644 --- a/src/scripts/test_python.py +++ b/src/scripts/test_python.py @@ -70,6 +70,7 @@ class BotanPythonTests(unittest.TestCase): def test_hmac(self): hmac = botan2.message_authentication_code('HMAC(SHA-256)') + self.assertEqual(hmac.algo_name(), 'HMAC(SHA-256)') hmac.set_key(hex_decode('0102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20')) hmac.update(hex_decode('616263')) @@ -93,6 +94,7 @@ class BotanPythonTests(unittest.TestCase): def test_hash(self): h = botan2.hash_function('SHA-256') + self.assertEqual(h.algo_name(), 'SHA-256') assert h.output_length() == 32 h.update('ignore this please') h.clear() @@ -109,6 +111,13 @@ class BotanPythonTests(unittest.TestCase): for mode in ['AES-128/CTR-BE', 'Serpent/GCM', 'ChaCha20Poly1305']: enc = botan2.cipher(mode, encrypt=True) + if mode == 'AES-128/CTR-BE': + self.assertEqual(enc.algo_name(), 'CTR-BE(AES-128)') + elif mode == 'Serpent/GCM': + self.assertEqual(enc.algo_name(), 'Serpent/GCM(16)') + else: + self.assertEqual(enc.algo_name(), mode) + (kmin, kmax) = enc.key_length() self.assertTrue(kmin <= kmax) @@ -151,10 +160,11 @@ class BotanPythonTests(unittest.TestCase): def test_rsa(self): rng = botan2.rng() rsapriv = botan2.private_key('RSA', '1024', rng) - rsapub = rsapriv.get_public_key() + self.assertEqual(rsapriv.algo_name(), 'RSA') - self.assertEqual(rsapub.estimated_strength(), 80) + rsapub = rsapriv.get_public_key() self.assertEqual(rsapub.algo_name(), 'RSA') + self.assertEqual(rsapub.estimated_strength(), 80) enc = botan2.pk_op_encrypt(rsapub, "OAEP(SHA-256)") dec = botan2.pk_op_decrypt(rsapriv, "OAEP(SHA-256)") |