-
Notifications
You must be signed in to change notification settings - Fork 175
/
errors.go
62 lines (50 loc) · 1.63 KB
/
errors.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package merkle
import (
"errors"
"fmt"
)
var ErrorIncompatibleKeyLength = errors.New("key has incompatible size")
// MalformedProofError is returned when a proof format
// has some issues (syntax checks).
type MalformedProofError struct {
err error
}
// NewMalformedProofErrorf constructs a new MalformedProofError
func NewMalformedProofErrorf(msg string, args ...interface{}) *MalformedProofError {
return &MalformedProofError{err: fmt.Errorf(msg, args...)}
}
func (e MalformedProofError) Error() string {
return fmt.Sprintf("malformed proof, %s", e.err.Error())
}
// Unwrap unwraps the error
func (e MalformedProofError) Unwrap() error {
return e.err
}
// IsMalformedProofError checks if err is a MalformedProofError
func IsMalformedProofError(err error) bool {
var target *MalformedProofError
return errors.As(err, &target)
}
// InvalidProofError is returned when proof
// verification has failed (semantic check).
// The most common case for this error is when the computed root hash
// doesn't match the root hash provided to the Verify method.
type InvalidProofError struct {
err error
}
// newInvalidProofErrorf constructs a new InvalidProofError
func newInvalidProofErrorf(msg string, args ...interface{}) *InvalidProofError {
return &InvalidProofError{err: fmt.Errorf(msg, args...)}
}
func (e InvalidProofError) Error() string {
return fmt.Sprintf("invalid proof, %s", e.err.Error())
}
// Unwrap unwraps the error
func (e InvalidProofError) Unwrap() error {
return e.err
}
// IsInvalidProofError checks if err is a InvalidProofError
func IsInvalidProofError(err error) bool {
var target *InvalidProofError
return errors.As(err, &target)
}