Skip to content

Commit

Permalink
check for both signatures and payload
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Aug 16, 2021
1 parent c36131f commit fb0a859
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion format.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
)

type formatHint struct {
Payload json.RawMessage `json:"payload"` // Only in JWS
Signatures json.RawMessage `json:"signatures"` // Only in JWS
Ciphertext json.RawMessage `json:"ciphertext"` // Only in JWE
KeyType json.RawMessage `json:"kty"` // Only in JWK
Expand Down Expand Up @@ -87,7 +88,7 @@ func GuessFormat(payload []byte) FormatKind {
if h.Ciphertext != nil {
return JWE
}
if h.Signatures != nil {
if h.Signatures != nil && h.Payload != nil {
return JWS
}
return UnknownFormat
Expand Down
2 changes: 1 addition & 1 deletion jwx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func TestGuessFormat(t *testing.T) {
{
Name: "JWS (JSON)",
Expected: jwx.JWS,
Source: []byte(`{"signatures": []}`),
Source: []byte(`{"signatures": [], "payload": ""}`),
},
{
Name: "JWT",
Expand Down

0 comments on commit fb0a859

Please sign in to comment.