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/EC.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/EC.py')
-rw-r--r-- | src/M2Crypto/EC.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/M2Crypto/EC.py b/src/M2Crypto/EC.py index 522092a..8cd052a 100644 --- a/src/M2Crypto/EC.py +++ b/src/M2Crypto/EC.py @@ -12,7 +12,6 @@ All rights reserved.""" from M2Crypto import BIO, Err, EVP, m2, util from typing import AnyStr, Callable, Dict, Optional, Tuple, Union # noqa -from M2Crypto.EVP import PKey EC_Key = bytes @@ -322,6 +321,16 @@ class EC_pub(EC): assert self.check_key(), 'key is not initialised' return m2.ec_key_get_public_key(self.ec) + def as_pem(self): + """ + Returns the key(pair) as a string in PEM format. + If no password is passed and the cipher is set + it exits with error + """ + with BIO.MemoryBuffer() as bio: + self.save_key_bio(bio) + return bio.read() + save_key = EC.save_pub_key save_key_bio = EC.save_pub_key_bio |