github.com/koko1123/flow-go-1@v0.29.6/storage/merkle/errors.go (about) 1 package merkle 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 var ErrorIncompatibleKeyLength = errors.New("key has incompatible size") 9 10 // MalformedProofError is returned when a proof format 11 // has some issues (syntax checks). 12 type MalformedProofError struct { 13 err error 14 } 15 16 // NewMalformedProofErrorf constructs a new MalformedProofError 17 func NewMalformedProofErrorf(msg string, args ...interface{}) *MalformedProofError { 18 return &MalformedProofError{err: fmt.Errorf(msg, args...)} 19 } 20 21 func (e MalformedProofError) Error() string { 22 return fmt.Sprintf("malformed proof, %s", e.err.Error()) 23 } 24 25 // Unwrap unwraps the error 26 func (e MalformedProofError) Unwrap() error { 27 return e.err 28 } 29 30 // IsMalformedProofError checks if err is a MalformedProofError 31 func IsMalformedProofError(err error) bool { 32 var target *MalformedProofError 33 return errors.As(err, &target) 34 } 35 36 // InvalidProofError is returned when proof 37 // verification has failed (semantic check). 38 // The most common case for this error is when the computed root hash 39 // doesn't match the root hash provided to the Verify method. 40 type InvalidProofError struct { 41 err error 42 } 43 44 // newInvalidProofErrorf constructs a new InvalidProofError 45 func newInvalidProofErrorf(msg string, args ...interface{}) *InvalidProofError { 46 return &InvalidProofError{err: fmt.Errorf(msg, args...)} 47 } 48 49 func (e InvalidProofError) Error() string { 50 return fmt.Sprintf("invalid proof, %s", e.err.Error()) 51 } 52 53 // Unwrap unwraps the error 54 func (e InvalidProofError) Unwrap() error { 55 return e.err 56 } 57 58 // IsInvalidProofError checks if err is a InvalidProofError 59 func IsInvalidProofError(err error) bool { 60 var target *InvalidProofError 61 return errors.As(err, &target) 62 }