Skip to content

Commit

Permalink
Changed the algorithm to be ed25519 rather than introduce a new type.
Browse files Browse the repository at this point in the history
Changed validation to lowercase the token type and algorithm before performing validity checks.
  • Loading branch information
aricart committed Sep 4, 2018
1 parent 0dc2798 commit b87335c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
)

// TokenTypeJwt is the JWT token type supported JWT tokens
// encoded and decoded by this library
const TokenTypeJwt = "JWT"
const TokenTypeJwt = "jwt"

// AlgorithmNkey is the algorithm supported by JWT tokens
// encoded and decoded by this library
const AlgorithmNkey = "NKEY"
const AlgorithmNkey = "ed25519"

// Header is a JWT Jose Header
type Header struct {
Expand Down Expand Up @@ -40,11 +41,11 @@ func parseHeaders(s string) (*Header, error) {
// Valid validates the Header. It returns nil if the Header is
// a JWT header, and the algorithm used is the NKEY algorithm.
func (h *Header) Valid() error {
if TokenTypeJwt != h.Type {
if TokenTypeJwt != strings.ToLower(h.Type) {
return fmt.Errorf("not supported type %q", h.Type)
}

if AlgorithmNkey != h.Algorithm {
if AlgorithmNkey != strings.ToLower(h.Algorithm) {
return fmt.Errorf("unexpected %q algorithm", h.Algorithm)
}
return nil
Expand Down

0 comments on commit b87335c

Please sign in to comment.