diff options
author | Bu Sun Kim <busunkim@google.com> | 2021-02-19 01:05:54 +0000 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2021-02-24 11:32:07 +0100 |
commit | eb6ddb6e3ec5cf3a512f1854adb6ed1ad318ea4e (patch) | |
tree | 46a57357f60a86d033d5fe80aab6b32393c589ec | |
parent | 758562f004ead1c999b297334d552b57404c21d2 (diff) | |
download | rsa-git-eb6ddb6e3ec5cf3a512f1854adb6ed1ad318ea4e.tar.gz |
Fix #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.
-rw-r--r-- | rsa/key.py | 2 | ||||
-rw-r--r-- | tests/test_load_save_keys.py | 5 |
2 files changed, 7 insertions, 0 deletions
@@ -251,6 +251,7 @@ class PublicKey(AbstractKey): def __setstate__(self, state: typing.Tuple[int, int]) -> None: """Sets the key from tuple.""" self.n, self.e = state + AbstractKey.__init__(self, self.n, self.e) def __eq__(self, other: typing.Any) -> bool: if other is None: @@ -426,6 +427,7 @@ class PrivateKey(AbstractKey): def __setstate__(self, state: typing.Tuple[int, int, int, int, int, int, int, int]) -> None: """Sets the key from tuple.""" self.n, self.e, self.d, self.p, self.q, self.exp1, self.exp2, self.coef = state + AbstractKey.__init__(self, self.n, self.e) def __eq__(self, other: typing.Any) -> bool: if other is None: diff --git a/tests/test_load_save_keys.py b/tests/test_load_save_keys.py index 7892fb3..d881d20 100644 --- a/tests/test_load_save_keys.py +++ b/tests/test_load_save_keys.py @@ -203,6 +203,9 @@ class PickleTest(unittest.TestCase): unpickled = pickle.loads(pickled) self.assertEqual(pk, unpickled) + for attr in rsa.key.AbstractKey.__slots__: + self.assertTrue(hasattr(unpickled, attr)) + def test_public_key(self): pk = rsa.key.PublicKey(3727264081, 65537) @@ -210,3 +213,5 @@ class PickleTest(unittest.TestCase): unpickled = pickle.loads(pickled) self.assertEqual(pk, unpickled) + for attr in rsa.key.AbstractKey.__slots__: + self.assertTrue(hasattr(unpickled, attr)) |