Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb6ddb6

Browse files
busunkim96sybrenstuvel
authored andcommitted
Fixsybrenstuvel#173: unpickling doesn't restore full object
When a `PrivateKey` or `PublicKey` is unpickled `AbstractKey.__init__()`should be called so `self.mutex` and `self.blindfac` are created.
1 parent758562f commiteb6ddb6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

‎rsa/key.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ def __getstate__(self) -> typing.Tuple[int, int]:
251251
def__setstate__(self,state:typing.Tuple[int,int])->None:
252252
"""Sets the key from tuple."""
253253
self.n,self.e=state
254+
AbstractKey.__init__(self,self.n,self.e)
254255

255256
def__eq__(self,other:typing.Any)->bool:
256257
ifotherisNone:
@@ -426,6 +427,7 @@ def __getstate__(self) -> typing.Tuple[int, int, int, int, int, int, int, int]:
426427
def__setstate__(self,state:typing.Tuple[int,int,int,int,int,int,int,int])->None:
427428
"""Sets the key from tuple."""
428429
self.n,self.e,self.d,self.p,self.q,self.exp1,self.exp2,self.coef=state
430+
AbstractKey.__init__(self,self.n,self.e)
429431

430432
def__eq__(self,other:typing.Any)->bool:
431433
ifotherisNone:

‎tests/test_load_save_keys.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,15 @@ def test_private_key(self):
203203
unpickled=pickle.loads(pickled)
204204
self.assertEqual(pk,unpickled)
205205

206+
forattrinrsa.key.AbstractKey.__slots__:
207+
self.assertTrue(hasattr(unpickled,attr))
208+
206209
deftest_public_key(self):
207210
pk=rsa.key.PublicKey(3727264081,65537)
208211

209212
pickled=pickle.dumps(pk)
210213
unpickled=pickle.loads(pickled)
211214

212215
self.assertEqual(pk,unpickled)
216+
forattrinrsa.key.AbstractKey.__slots__:
217+
self.assertTrue(hasattr(unpickled,attr))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp