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