aboutsummaryrefslogtreecommitdiffstats
path: root/src/python/botan2.py
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-04-18 13:22:00 -0400
committerJack Lloyd <[email protected]>2019-04-18 13:22:00 -0400
commit36deb985ac7be417d883b9b42b14295b43f1cc6d (patch)
tree184eafca39f7784e1231bd9b131a6762c5a0c60b /src/python/botan2.py
parent8d844e50aa11171de6f4abbfd65464a75b317da2 (diff)
Add missing export functions
Fixes #1899
Diffstat (limited to 'src/python/botan2.py')
-rwxr-xr-xsrc/python/botan2.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/python/botan2.py b/src/python/botan2.py
index e90968fa0..19348f6aa 100755
--- a/src/python/botan2.py
+++ b/src/python/botan2.py
@@ -257,7 +257,7 @@ botan.botan_privkey_export_pubkey.errcheck = errcheck_for('botan_privkey_export_
botan.botan_privkey_destroy.argtypes = [c_void_p]
botan.botan_privkey_destroy.errcheck = errcheck_for('botan_privkey_destroy')
-botan.botan_privkey_export.argtypes = [c_void_p, POINTER(c_char), c_void_p]
+botan.botan_privkey_export.argtypes = [c_void_p, POINTER(c_char), c_void_p, c_uint32]
botan.botan_privkey_export.errcheck = errcheck_for('botan_privkey_export')
# PK Encryption
@@ -871,10 +871,19 @@ class PublicKey(object): # pylint: disable=invalid-name
def algo_name(self):
return _call_fn_returning_string(32, lambda b, bl: botan.botan_pubkey_algo_name(self.__obj, b, bl))
- def encoding(self, pem=False):
+ def export(self, pem=False):
flag = 1 if pem else 0
return _call_fn_returning_vec(4096, lambda b, bl: botan.botan_pubkey_export(self.__obj, b, bl, flag))
+ def encoding(self, pem=False):
+ return self.export(pem)
+
+ def to_der(self):
+ return self.export(False)
+
+ def to_pem(self):
+ return self.export(True)
+
def fingerprint(self, hash_algorithm='SHA-256'):
n = HashFunction(hash_algorithm).output_length()
@@ -927,17 +936,15 @@ class PrivateKey(object):
botan.botan_privkey_export_pubkey(byref(pub), self.__obj)
return public_key(pub)
- def export(self):
+ def to_der(self):
+ return self.export(False)
- n = 4096
- buf = create_string_buffer(n)
- buf_len = c_size_t(n)
+ def to_pem(self):
+ return self.export(True)
- rc = botan.botan_privkey_export(self.__obj, buf, byref(buf_len))
- if rc != 0:
- buf = create_string_buffer(buf_len.value)
- botan.botan_privkey_export(self.__obj, buf, byref(buf_len))
- return buf[0:int(buf_len.value)]
+ def export(self, pem=False):
+ flag = 1 if pem else 0
+ return _call_fn_returning_vec(4096, lambda b, bl: botan.botan_privkey_export(self.__obj, b, bl, flag))
class PKEncrypt(object):
def __init__(self, key, padding):