| 55 | } |
| 56 | |
| 57 | func TestDefaultHashSignVerifierImpl(t *testing.T) { |
| 58 | Convey("Given a dummy object and a pair of keys", t, func() { |
| 59 | var ( |
| 60 | obj = &DummyObject{} |
| 61 | priv, _, err = asymmetric.GenSecp256k1KeyPair() |
| 62 | ) |
| 63 | So(err, ShouldBeNil) |
| 64 | So(priv, ShouldNotBeNil) |
| 65 | Convey("When the object is signed by the key pair", func() { |
| 66 | err = obj.Sign(priv) |
| 67 | So(err, ShouldBeNil) |
| 68 | Convey("The object should be verifiable", func() { |
| 69 | err = obj.Verify() |
| 70 | So(err, ShouldBeNil) |
| 71 | }) |
| 72 | Convey("The object should have data hash", func() { |
| 73 | So(obj.Hash(), ShouldEqual, hash.THashH(dummyHash)) |
| 74 | }) |
| 75 | Convey("When the hash is modified", func() { |
| 76 | obj.DefaultHashSignVerifierImpl.DataHash = hash.Hash{0x0, 0x0, 0x0, 0x1} |
| 77 | Convey("The verifier should return hash value not match error", func() { |
| 78 | err = obj.Verify() |
| 79 | So(err, ShouldEqual, ErrHashValueNotMatch) |
| 80 | }) |
| 81 | }) |
| 82 | Convey("When the signee is modified", func() { |
| 83 | var _, pub, err = asymmetric.GenSecp256k1KeyPair() |
| 84 | So(err, ShouldBeNil) |
| 85 | obj.DefaultHashSignVerifierImpl.Signee = pub |
| 86 | Convey("The verifier should return signature not match error", func() { |
| 87 | err = obj.Verify() |
| 88 | So(err, ShouldEqual, ErrSignatureNotMatch) |
| 89 | }) |
| 90 | }) |
| 91 | Convey("When the signature is modified", func() { |
| 92 | var val = obj.DefaultHashSignVerifierImpl.Signature.R |
| 93 | val.Add(val, big.NewInt(1)) |
| 94 | Convey("The verifier should return signature not match error", func() { |
| 95 | err = obj.Verify() |
| 96 | So(err, ShouldEqual, ErrSignatureNotMatch) |
| 97 | }) |
| 98 | }) |
| 99 | }) |
| 100 | }) |
| 101 | } |