...

Source file src/github.com/decred/dcrd/dcrec/secp256k1/v4/error.go

Documentation: github.com/decred/dcrd/dcrec/secp256k1/v4

     1  // Copyright (c) 2020 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package secp256k1
     6  
     7  // ErrorKind identifies a kind of error.  It has full support for errors.Is and
     8  // errors.As, so the caller can directly check against an error kind when
     9  // determining the reason for an error.
    10  type ErrorKind string
    11  
    12  // These constants are used to identify a specific RuleError.
    13  const (
    14  	// ErrPubKeyInvalidLen indicates that the length of a serialized public
    15  	// key is not one of the allowed lengths.
    16  	ErrPubKeyInvalidLen = ErrorKind("ErrPubKeyInvalidLen")
    17  
    18  	// ErrPubKeyInvalidFormat indicates an attempt was made to parse a public
    19  	// key that does not specify one of the supported formats.
    20  	ErrPubKeyInvalidFormat = ErrorKind("ErrPubKeyInvalidFormat")
    21  
    22  	// ErrPubKeyXTooBig indicates that the x coordinate for a public key
    23  	// is greater than or equal to the prime of the field underlying the group.
    24  	ErrPubKeyXTooBig = ErrorKind("ErrPubKeyXTooBig")
    25  
    26  	// ErrPubKeyYTooBig indicates that the y coordinate for a public key is
    27  	// greater than or equal to the prime of the field underlying the group.
    28  	ErrPubKeyYTooBig = ErrorKind("ErrPubKeyYTooBig")
    29  
    30  	// ErrPubKeyNotOnCurve indicates that a public key is not a point on the
    31  	// secp256k1 curve.
    32  	ErrPubKeyNotOnCurve = ErrorKind("ErrPubKeyNotOnCurve")
    33  
    34  	// ErrPubKeyMismatchedOddness indicates that a hybrid public key specified
    35  	// an oddness of the y coordinate that does not match the actual oddness of
    36  	// the provided y coordinate.
    37  	ErrPubKeyMismatchedOddness = ErrorKind("ErrPubKeyMismatchedOddness")
    38  )
    39  
    40  // Error satisfies the error interface and prints human-readable errors.
    41  func (e ErrorKind) Error() string {
    42  	return string(e)
    43  }
    44  
    45  // Error identifies an error related to public key cryptography using a
    46  // sec256k1 curve. It has full support for errors.Is and errors.As, so the
    47  // caller can  ascertain the specific reason for the error by checking
    48  // the underlying error.
    49  type Error struct {
    50  	Err         error
    51  	Description string
    52  }
    53  
    54  // Error satisfies the error interface and prints human-readable errors.
    55  func (e Error) Error() string {
    56  	return e.Description
    57  }
    58  
    59  // Unwrap returns the underlying wrapped error.
    60  func (e Error) Unwrap() error {
    61  	return e.Err
    62  }
    63  
    64  // makeError creates an Error given a set of arguments.
    65  func makeError(kind ErrorKind, desc string) Error {
    66  	return Error{Err: kind, Description: desc}
    67  }
    68  

View as plain text