forked from nanu-c/zkgroup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
45 lines (37 loc) · 1.01 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package zkgroup
/*
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_x86_64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_aarch64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_armv7
#include "lib/zkgroup.h"
*/
import "C"
import (
"errors"
"fmt"
)
// ErrVerificationFailed if verification failed.
var ErrVerificationFailed = errors.New("verification failed")
// ErrInternal if internal error.
var ErrInternal = errors.New("internal error")
// ErrInvalidInput if invalid input.
var ErrInvalidInput = errors.New("invalid input")
// Error is a generic error with code.
type Error struct {
Code int
}
func errFromCode(code C.int) error {
switch code {
case C.FFI_RETURN_OK:
return nil
case C.FFI_RETURN_INTERNAL_ERROR:
return ErrInternal
case C.FFI_RETURN_INPUT_ERROR:
return ErrInvalidInput
default:
return Error{Code: int(code)}
}
}
func (e Error) Error() string {
return fmt.Sprintf("zkgroup error %d", e.Code)
}