Skip to content

Commit

Permalink
Fix logging of recovered in NewPublicNymFromBytes
Browse files Browse the repository at this point in the history
By using the same identifier for a named return and the result of
recover, the code inadvertently cleared the recover result before
logging instead of clearly the result of the function.

Signed-off-by: Matthew Sykes <matthew.sykes@gmail.com>
  • Loading branch information
sykesm committed Jun 25, 2020
1 parent 52436d3 commit 3e29ecd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bccsp/idemix/bridge/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ var _ = Describe("Idemix Bridge", func() {

It("panic on nil raw", func() {
key, err := User.NewPublicNymFromBytes(nil)
Expect(err).To(MatchError("failure [%!s(<nil>)]"))
Expect(err).To(MatchError("failure [runtime error: index out of range [0] with length 0]"))
Expect(key).To(BeNil())
})

It("failure unmarshalling invalid raw", func() {
key, err := User.NewPublicNymFromBytes([]byte{0, 1, 2, 3})
Expect(err).To(MatchError("failure [%!s(<nil>)]"))
Expect(err).To(MatchError("failure [runtime error: index out of range [2] with length 2]"))
Expect(key).To(BeNil())
})

Expand Down
6 changes: 3 additions & 3 deletions bccsp/idemix/bridge/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ func (u *User) MakeNym(sk handlers.Big, ipk handlers.IssuerPublicKey) (r1 handle
return
}

func (*User) NewPublicNymFromBytes(raw []byte) (r handlers.Ecp, err error) {
func (*User) NewPublicNymFromBytes(raw []byte) (res handlers.Ecp, err error) {
defer func() {
if r := recover(); r != nil {
r = nil
res = nil
err = errors.Errorf("failure [%s]", r)
}
}()

// raw is the concatenation of two big integers
lHalve := len(raw) / 2

r = &Ecp{E: FP256BN.NewECPbigs(FP256BN.FromBytes(raw[:lHalve]), FP256BN.FromBytes(raw[lHalve:]))}
res = &Ecp{E: FP256BN.NewECPbigs(FP256BN.FromBytes(raw[:lHalve]), FP256BN.FromBytes(raw[lHalve:]))}

return
}

0 comments on commit 3e29ecd

Please sign in to comment.