From 73548e47d9b0168adcc5458a5b8441c128d95661 Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Thu, 24 Oct 2024 14:00:27 +0900 Subject: [PATCH] get the type / var name correct --- jws/errors.go | 56 +++++++++++++++++++++++++-------------------------- jws/jws.go | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/jws/errors.go b/jws/errors.go index 2a758fea..d5e1762a 100644 --- a/jws/errors.go +++ b/jws/errors.go @@ -4,99 +4,99 @@ import ( "fmt" ) -type errSign struct { +type signError struct { error } -var emptySignErr = errSign{fmt.Errorf(`jws.Sign: unknown error`)} +var errDefaultSignError = signerr(`unknown error`) // SignError returns an error that can be passed to `errors.Is` to check if the error is a sign error. func SignError() error { - return emptySignErr + return errDefaultSignError } -func (e errSign) Unwrap() error { +func (e signError) Unwrap() error { return e.error } -func (errSign) Is(err error) bool { - _, ok := err.(errSign) +func (signError) Is(err error) bool { + _, ok := err.(signError) return ok } func signerr(f string, args ...any) error { - return errSign{fmt.Errorf(`jws.Sign: `+f, args...)} + return signError{fmt.Errorf(`jws.Sign: `+f, args...)} } // This error is returned when jws.Verify fails, but note that there's another type of // message that can be returned by jws.Verify, which is `errVerification`. -type errVerify struct { +type verifyError struct { error } -var emptyVerifyErr = errVerify{fmt.Errorf(`jws.Verify: unknown error`)} +var errDefaultVerifyError = verifyerr(`unknown error`) // VerifyError returns an error that can be passed to `errors.Is` to check if the error is a verify error. func VerifyError() error { - return emptyVerifyErr + return errDefaultVerifyError } -func (e errVerify) Unwrap() error { +func (e verifyError) Unwrap() error { return e.error } -func (errVerify) Is(err error) bool { - _, ok := err.(errVerify) +func (verifyError) Is(err error) bool { + _, ok := err.(verifyError) return ok } func verifyerr(f string, args ...any) error { - return errVerify{fmt.Errorf(`jws.Verify: `+f, args...)} + return verifyError{fmt.Errorf(`jws.Verify: `+f, args...)} } -// errVerification is returned when the actual _verification_ of the key/payload fails. -type errVerification struct { +// verificationError is returned when the actual _verification_ of the key/payload fails. +type verificationError struct { error } -var emptyVerificationErr = errVerification{fmt.Errorf(`jws.Verify: unknown error`)} +var errDefaultVerificationError = verificationError{fmt.Errorf(`unknown verification error`)} // VerificationError returns an error that can be passed to `errors.Is` to check if the error is a verification error. func VerificationError() error { - return emptyVerificationErr + return errDefaultVerificationError } -func (e errVerification) Unwrap() error { +func (e verificationError) Unwrap() error { return e.error } -func (errVerification) Is(err error) bool { - _, ok := err.(errVerification) +func (verificationError) Is(err error) bool { + _, ok := err.(verificationError) return ok } -type errParse struct { +type parseError struct { error } -var emptyParseErr = errParse{fmt.Errorf(`jws.Parse: unknown error`)} +var errDefaultParseError = parseerr(`unknown error`) // ParseError returns an error that can be passed to `errors.Is` to check if the error is a parse error. func ParseError() error { - return emptyParseErr + return errDefaultParseError } -func (e errParse) Unwrap() error { +func (e parseError) Unwrap() error { return e.error } -func (errParse) Is(err error) bool { - _, ok := err.(errParse) +func (parseError) Is(err error) bool { + _, ok := err.(parseError) return ok } func bparseerr(prefix string, f string, args ...any) error { - return errParse{fmt.Errorf(prefix+": "+f, args...)} + return parseError{fmt.Errorf(prefix+": "+f, args...)} } func parseerr(f string, args ...any) error { diff --git a/jws/jws.go b/jws/jws.go index f035e5cd..8a4b5452 100644 --- a/jws/jws.go +++ b/jws/jws.go @@ -442,7 +442,7 @@ func Verify(buf []byte, options ...VerifyOption) ([]byte, error) { } if err := verifier.Verify(verifyBuf.Bytes(), sig.signature, key); err != nil { - errs = append(errs, errVerification{err}) + errs = append(errs, verificationError{err}) continue }