diff --git a/src/ecdsa/ellipticcurve.py b/src/ecdsa/ellipticcurve.py index c016b8b8..1bbccb5b 100644 --- a/src/ecdsa/ellipticcurve.py +++ b/src/ecdsa/ellipticcurve.py @@ -101,6 +101,9 @@ def __eq__(self, other): ) return NotImplemented + def __ne__(self, other): + return not (self == other) + def __hash__(self): return hash((self.__p, self.__a, self.__b)) @@ -185,6 +188,19 @@ def __init__(self, curve, x, y, z, order=None, generator=False): doubler = doubler.double().scale() self.__precompute.append((doubler.x(), doubler.y())) + def __getstate__(self): + try: + self._scale_lock.reader_acquire() + state = self.__dict__.copy() + finally: + self._scale_lock.reader_release() + del state["_scale_lock"] + return state + + def __setstate__(self, state): + self.__dict__.update(state) + self._scale_lock = RWLock() + def __eq__(self, other): """Compare two points with each-other.""" try: diff --git a/src/ecdsa/test_ellipticcurve.py b/src/ecdsa/test_ellipticcurve.py index 6b711fb3..def53b2a 100644 --- a/src/ecdsa/test_ellipticcurve.py +++ b/src/ecdsa/test_ellipticcurve.py @@ -195,6 +195,6 @@ def test_inequality_points(self): p = Point(c, 100, 100, 100) self.assertNotEqual(self.g_23, p) - def test_inaquality_points_diff_types(self): + def test_inequality_points_diff_types(self): c = CurveFp(100, -3, 100) self.assertNotEqual(self.g_23, c) diff --git a/src/ecdsa/test_jacobi.py b/src/ecdsa/test_jacobi.py index 7c806f6f..5494243d 100644 --- a/src/ecdsa/test_jacobi.py +++ b/src/ecdsa/test_jacobi.py @@ -1,3 +1,5 @@ +import pickle + try: import unittest2 as unittest except ImportError: @@ -6,7 +8,7 @@ import hypothesis.strategies as st from hypothesis import given, assume, settings, example -from .ellipticcurve import Point, PointJacobi, INFINITY +from .ellipticcurve import CurveFp, Point, PointJacobi, INFINITY from .ecdsa import generator_256, curve_256, generator_224 from .numbertheory import inverse_mod @@ -384,3 +386,12 @@ def test_mul_add_large(self): self.assertEqual( j_g * (0xFF00 + 255 * 0xF0F0), j_g.mul_add(0xFF00, b, 0xF0F0) ) + + def test_equality(self): + pj1 = PointJacobi(curve=CurveFp(23, 1, 1, 1), x=2, y=3, z=1, order=1) + pj2 = PointJacobi(curve=CurveFp(23, 1, 1, 1), x=2, y=3, z=1, order=1) + self.assertEqual(pj1, pj2) + + def test_pickle(self): + pj = PointJacobi(curve=CurveFp(23, 1, 1, 1), x=2, y=3, z=1, order=1) + self.assertEqual(pickle.loads(pickle.dumps(pj)), pj)