diff options
author | Mohd Saquib <mohd.saquib@suse.com> | 2023-02-02 21:02:32 +0530 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2023-02-03 16:20:55 +0100 |
commit | 048512359851ae1d1622e9d6f9c8c8575cb02fa8 (patch) | |
tree | 0733d9cf0beeafd0920ac9ba002b61f9236c7338 /src/M2Crypto/EVP.py | |
parent | b6917efc045dfdb5fb40804f88c7ade2c2841677 (diff) | |
download | m2crypto-048512359851ae1d1622e9d6f9c8c8575cb02fa8.tar.gz |
Add functionality to extract EC key from public key + Update tests
Fixes #124
Diffstat (limited to 'src/M2Crypto/EVP.py')
-rw-r--r-- | src/M2Crypto/EVP.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/M2Crypto/EVP.py b/src/M2Crypto/EVP.py index c48b670..de2dcef 100644 --- a/src/M2Crypto/EVP.py +++ b/src/M2Crypto/EVP.py @@ -9,7 +9,7 @@ Author: Heikki Toivonen """ import logging -from M2Crypto import BIO, Err, RSA, m2, util +from M2Crypto import BIO, Err, RSA, EC, m2, util from typing import AnyStr, Optional, Callable # noqa log = logging.getLogger('EVP') @@ -385,6 +385,38 @@ class PKey(object): rsa = RSA.RSA_pub(rsa_ptr, 1) return rsa + def assign_ec(self, ec, capture=1): + # type: (EC.EC, int) -> int + """ + Assign the EC key pair to self. + + :param ec: M2Crypto.EC.EC object to be assigned to self. + + :param capture: If true (default), this PKey object will own the EC + object, meaning that once the PKey object gets + deleted it is no longer safe to use the EC object. + + :return: Return 1 for success and 0 for failure. + """ + if capture: + ret = m2.pkey_assign_ec(self.pkey, ec.ec) + if ret: + ec._pyfree = 0 + else: + ret = m2.pkey_set1_ec(self.pkey, ec.ec) + return ret + + def get_ec(self): + # type: () -> EC.EC_pub + """ + Return the underlying EC key if that is what the EVP + instance is holding. + """ + ec_ptr = m2.pkey_get1_ec(self.pkey) + + ec = EC.EC_pub(ec_ptr) + return ec + def save_key(self, file, cipher='aes_128_cbc', callback=util.passphrase_callback): # type: (AnyStr, Optional[str], Callable) -> int |