Skip to content

Commit

Permalink
make m2crypto backed public key pickleable
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed Feb 2, 2022
1 parent 38dbe7d commit ecf05a2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tlslite/utils/openssl_rsakey.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ def __init__(self, n=0, e=0, key_type="rsa"):
m2.rsa_set_e(self.rsa, numberToMPI(e))
self.key_type = key_type

def __getstate__(self):
if not self.rsa:
return (self.key_type, )
return (self.key_type,
mpiToNumber(m2.rsa_get_e(self.rsa)),
mpiToNumber(m2.rsa_get_n(self.rsa)))

def __setstate__(self, state):
self.rsa = None
self._hasPrivateKey = False
self.key_type = state[0]
if len(state) > 1:
self.rsa = m2.rsa_new()
m2.rsa_set_e(self.rsa, numberToMPI(state[1]))
m2.rsa_set_n(self.rsa, numberToMPI(state[2]))

def __del__(self):
if self.rsa:
m2.rsa_free(self.rsa)
Expand Down

0 comments on commit ecf05a2

Please sign in to comment.