Skip to content

Commit

Permalink
Instantiate errors using wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrlsnchs committed Sep 14, 2019
1 parent e58f6e0 commit 37314c1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 30 deletions.
7 changes: 3 additions & 4 deletions ecdsa_sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import (
"crypto"
"crypto/ecdsa"
"crypto/rand"
"errors"
"math/big"

"github.com/gbrlsnchs/jwt/v3/internal"
)

var (
// ErrECDSANilPrivKey is the error for trying to sign a JWT with a nil private key.
ErrECDSANilPrivKey = errors.New("jwt: ECDSA private key is nil")
ErrECDSANilPrivKey = internal.NewError("jwt: ECDSA private key is nil")
// ErrECDSANilPubKey is the error for trying to verify a JWT with a nil public key.
ErrECDSANilPubKey = errors.New("jwt: ECDSA public key is nil")
ErrECDSANilPubKey = internal.NewError("jwt: ECDSA public key is nil")
// ErrECDSAVerification is the error for an invalid ECDSA signature.
ErrECDSAVerification = errors.New("jwt: ECDSA verification failed")
ErrECDSAVerification = internal.NewError("jwt: ECDSA verification failed")

_ Algorithm = new(ECDSASHA)
)
Expand Down
7 changes: 3 additions & 4 deletions ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ package jwt

import (
"crypto/ed25519"
"errors"

"github.com/gbrlsnchs/jwt/v3/internal"
)

var (
// ErrEd25519NilPrivKey is the error for trying to sign a JWT with a nil private key.
ErrEd25519NilPrivKey = errors.New("jwt: Ed25519 private key is nil")
ErrEd25519NilPrivKey = internal.NewError("jwt: Ed25519 private key is nil")
// ErrEd25519NilPubKey is the error for trying to verify a JWT with a nil public key.
ErrEd25519NilPubKey = errors.New("jwt: Ed25519 public key is nil")
ErrEd25519NilPubKey = internal.NewError("jwt: Ed25519 public key is nil")
// ErrEd25519Verification is the error for when verification with Ed25519 fails.
ErrEd25519Verification = errors.New("jwt: Ed25519 verification failed")
ErrEd25519Verification = internal.NewError("jwt: Ed25519 verification failed")

_ Algorithm = new(Ed25519)
)
Expand Down
8 changes: 3 additions & 5 deletions ed25519_go1_12.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
package jwt

import (
"errors"

"github.com/gbrlsnchs/jwt/v3/internal"
"golang.org/x/crypto/ed25519"
)

var (
// ErrEd25519NilPrivKey is the error for trying to sign a JWT with a nil private key.
ErrEd25519NilPrivKey = errors.New("jwt: Ed25519 private key is nil")
ErrEd25519NilPrivKey = internal.NewError("jwt: Ed25519 private key is nil")
// ErrEd25519NilPubKey is the error for trying to verify a JWT with a nil public key.
ErrEd25519NilPubKey = errors.New("jwt: Ed25519 public key is nil")
ErrEd25519NilPubKey = internal.NewError("jwt: Ed25519 public key is nil")
// ErrEd25519Verification is the error for when verification with Ed25519 fails.
ErrEd25519Verification = errors.New("jwt: Ed25519 verification failed")
ErrEd25519Verification = internal.NewError("jwt: Ed25519 verification failed")

_ Algorithm = new(Ed25519)
)
Expand Down
5 changes: 2 additions & 3 deletions hmac_sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package jwt
import (
"crypto"
"crypto/hmac"
"errors"
"hash"

"github.com/gbrlsnchs/jwt/v3/internal"
)

var (
// ErrHMACMissingKey is the error for trying to sign or verify a JWT with an empty key.
ErrHMACMissingKey = errors.New("jwt: HMAC key is empty")
ErrHMACMissingKey = internal.NewError("jwt: HMAC key is empty")
// ErrHMACVerification is the error for an invalid signature.
ErrHMACVerification = errors.New("jwt: HMAC verification failed")
ErrHMACVerification = internal.NewError("jwt: HMAC verification failed")

_ Algorithm = new(HMACSHA)
)
Expand Down
3 changes: 1 addition & 2 deletions raw_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package jwt

import (
"encoding/json"
"errors"

"github.com/gbrlsnchs/jwt/v3/internal"
)

// ErrMalformed indicates a token doesn't have a valid format, as per the RFC 7519.
var ErrMalformed = errors.New("jwt: malformed token")
var ErrMalformed = internal.NewError("jwt: malformed token")

// RawToken is a representation of a parsed JWT string.
type RawToken struct {
Expand Down
7 changes: 3 additions & 4 deletions rsa_sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import (
"crypto"
"crypto/rand"
"crypto/rsa"
"errors"

"github.com/gbrlsnchs/jwt/v3/internal"
)

var (
// ErrRSANilPrivKey is the error for trying to sign a JWT with a nil private key.
ErrRSANilPrivKey = errors.New("jwt: RSA private key is nil")
ErrRSANilPrivKey = internal.NewError("jwt: RSA private key is nil")
// ErrRSANilPubKey is the error for trying to verify a JWT with a nil public key.
ErrRSANilPubKey = errors.New("jwt: RSA public key is nil")
ErrRSANilPubKey = internal.NewError("jwt: RSA public key is nil")
// ErrRSAVerification is the error for an invalid RSA signature.
ErrRSAVerification = errors.New("jwt: RSA verification failed")
ErrRSAVerification = internal.NewError("jwt: RSA verification failed")

_ Algorithm = new(RSASHA)
)
Expand Down
17 changes: 9 additions & 8 deletions validators.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package jwt

import (
"errors"
"time"

"github.com/gbrlsnchs/jwt/v3/internal"
)

var (
// ErrAudValidation is the error for an invalid "aud" claim.
ErrAudValidation = errors.New("jwt: aud claim is invalid")
ErrAudValidation = internal.NewError("jwt: aud claim is invalid")
// ErrExpValidation is the error for an invalid "exp" claim.
ErrExpValidation = errors.New("jwt: exp claim is invalid")
ErrExpValidation = internal.NewError("jwt: exp claim is invalid")
// ErrIatValidation is the error for an invalid "iat" claim.
ErrIatValidation = errors.New("jwt: iat claim is invalid")
ErrIatValidation = internal.NewError("jwt: iat claim is invalid")
// ErrIssValidation is the error for an invalid "iss" claim.
ErrIssValidation = errors.New("jwt: iss claim is invalid")
ErrIssValidation = internal.NewError("jwt: iss claim is invalid")
// ErrJtiValidation is the error for an invalid "jti" claim.
ErrJtiValidation = errors.New("jwt: jti claim is invalid")
ErrJtiValidation = internal.NewError("jwt: jti claim is invalid")
// ErrNbfValidation is the error for an invalid "nbf" claim.
ErrNbfValidation = errors.New("jwt: nbf claim is invalid")
ErrNbfValidation = internal.NewError("jwt: nbf claim is invalid")
// ErrSubValidation is the error for an invalid "sub" claim.
ErrSubValidation = errors.New("jwt: sub claim is invalid")
ErrSubValidation = internal.NewError("jwt: sub claim is invalid")
)

// Validator is a function that validates a Payload pointer.
Expand Down

0 comments on commit 37314c1

Please sign in to comment.