Skip to content

Commit ecf05a2

Browse files
committed
make m2crypto backed public key pickleable
1 parent 38dbe7d commit ecf05a2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tlslite/utils/openssl_rsakey.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ def __init__(self, n=0, e=0, key_type="rsa"):
4343
m2.rsa_set_e(self.rsa, numberToMPI(e))
4444
self.key_type = key_type
4545

46+
def __getstate__(self):
47+
if not self.rsa:
48+
return (self.key_type, )
49+
return (self.key_type,
50+
mpiToNumber(m2.rsa_get_e(self.rsa)),
51+
mpiToNumber(m2.rsa_get_n(self.rsa)))
52+
53+
def __setstate__(self, state):
54+
self.rsa = None
55+
self._hasPrivateKey = False
56+
self.key_type = state[0]
57+
if len(state) > 1:
58+
self.rsa = m2.rsa_new()
59+
m2.rsa_set_e(self.rsa, numberToMPI(state[1]))
60+
m2.rsa_set_n(self.rsa, numberToMPI(state[2]))
61+
4662
def __del__(self):
4763
if self.rsa:
4864
m2.rsa_free(self.rsa)

0 commit comments

Comments
 (0)