From 048512359851ae1d1622e9d6f9c8c8575cb02fa8 Mon Sep 17 00:00:00 2001 From: Mohd Saquib Date: Thu, 2 Feb 2023 21:02:32 +0530 Subject: Add functionality to extract EC key from public key + Update tests Fixes #124 --- src/M2Crypto/EC.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/M2Crypto/EC.py') 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 -- cgit v1.2.1