error.mx raw

   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  	// ErrPubKeyInvalidFormat indicates an attempt was made to parse a public
  18  	// key that does not specify one of the supported formats.
  19  	ErrPubKeyInvalidFormat = ErrorKind("ErrPubKeyInvalidFormat")
  20  	// ErrPubKeyXTooBig indicates that the x coordinate for a public key
  21  	// is greater than or equal to the prime of the field underlying the group.
  22  	ErrPubKeyXTooBig = ErrorKind("ErrPubKeyXTooBig")
  23  	// ErrPubKeyYTooBig indicates that the y coordinate for a public key is
  24  	// greater than or equal to the prime of the field underlying the group.
  25  	ErrPubKeyYTooBig = ErrorKind("ErrPubKeyYTooBig")
  26  	// ErrPubKeyNotOnCurve indicates that a public key is not a point on the
  27  	// secp256k1 curve.
  28  	ErrPubKeyNotOnCurve = ErrorKind("ErrPubKeyNotOnCurve")
  29  	// ErrPubKeyMismatchedOddness indicates that a hybrid public key specified
  30  	// an oddness of the y coordinate that does not match the actual oddness of
  31  	// the provided y coordinate.
  32  	ErrPubKeyMismatchedOddness = ErrorKind("ErrPubKeyMismatchedOddness")
  33  )
  34  
  35  // Error satisfies the error interface and prints human-readable errors.
  36  func (err ErrorKind) Error() string { return string(err) }
  37  
  38  // Error identifies an error related to public key cryptography using a
  39  // sec256k1 curve. It has full support for errors.Is and errors.As, so the
  40  // caller can  ascertain the specific reason for the error by checking
  41  // the underlying error.
  42  type Error struct {
  43  	Err         error
  44  	Description string
  45  }
  46  
  47  // Error satisfies the error interface and prints human-readable errors.
  48  func (err Error) Error() string { return err.Description }
  49  
  50  // Unwrap returns the underlying wrapped error.
  51  func (err Error) Unwrap() (ee error) { return err.Err }
  52  
  53  // makeError creates an Error given a set of arguments.
  54  func makeError(kind ErrorKind, desc string) (err error) {
  55  	return Error{Err: kind, Description: string(append([]byte(nil), desc...))}
  56  }
  57