From 7fa929adb4b7086241dba7d0b262377d10a6f357 Mon Sep 17 00:00:00 2001 From: decanus <7621705+decanus@users.noreply.github.com> Date: Mon, 13 Sep 2021 23:15:01 +0200 Subject: [PATCH] cleanup --- rln/rln.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rln/rln.go b/rln/rln.go index 2b1f200..2ea16fd 100644 --- a/rln/rln.go +++ b/rln/rln.go @@ -62,15 +62,18 @@ func (r *RLN) GenerateKey() (*KeyPair, error) { return key, nil } -func (r *RLN) Hash(input []byte) []byte { +// Hash hashes a given input using the underlying function. +func (r *RLN) Hash(input []byte) ([]byte, error) { size := int(unsafe.Sizeof(C.Buffer{})) in := (*C.Buffer)(C.malloc(C.size_t(size))) *in = toBuffer(input) out := (*C.Buffer)(C.malloc(C.size_t(size))) - C.hash(r.ptr, in, &in.len, out) + if !bool(C.hash(r.ptr, in, &in.len, out)) { + return nil, errors.New("failed to hash") + } - return C.GoBytes(unsafe.Pointer(out.ptr), C.int(out.len)) + return C.GoBytes(unsafe.Pointer(out.ptr), C.int(out.len)), nil } func (r *RLN) CircuitFromParams(depth int, parameters []byte) bool {