Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmark committed Jun 4, 2022
1 parent b96f144 commit 77b5186
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
6 changes: 2 additions & 4 deletions src/JWT/Builder/JwtBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ public JwtBuilder WithSecret(params byte[][] secrets)
/// Instructs to verify the JWT signature.
/// </summary>
/// <returns>Current builder instance</returns>
public JwtBuilder MustVerifySignature()
{
return WithVerifySignature(true);
}
public JwtBuilder MustVerifySignature() =>
WithVerifySignature(true);

/// <summary>
/// Instructs to do not verify the JWT signature.
Expand Down
24 changes: 12 additions & 12 deletions src/JWT/JwtDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,7 @@ public string Decode(JwtParts jwt, byte[] key, bool verify)
}
else
{
var header = DecodeHeader<JwtHeader>(jwt);
if (String.Equals(header.Algorithm, nameof(JwtAlgorithmName.None), StringComparison.OrdinalIgnoreCase) &&
!String.IsNullOrEmpty(jwt.Signature))
{
throw new InvalidOperationException("Signature is not acceptable for algorithm None");
}
ValidateNoneAlgorithm(jwt);
}
return Decode(jwt);
}
Expand All @@ -157,12 +152,7 @@ public string Decode(JwtParts jwt, byte[][] keys, bool verify)
}
else
{
var header = DecodeHeader<JwtHeader>(jwt);
if (String.Equals(header.Algorithm, nameof(JwtAlgorithmName.None), StringComparison.OrdinalIgnoreCase) &&
!String.IsNullOrEmpty(jwt.Signature))
{
throw new InvalidOperationException("Signature is not acceptable for algorithm None");
}
ValidateNoneAlgorithm(jwt);
}
return Decode(jwt);
}
Expand Down Expand Up @@ -289,5 +279,15 @@ private static bool AllKeysHaveValues(byte[][] keys)

return Array.TrueForAll(keys, key => key.Length > 0);
}

private void ValidateNoneAlgorithm(JwtParts jwt)
{
var header = DecodeHeader<JwtHeader>(jwt);
if (String.Equals(header.Algorithm, nameof(JwtAlgorithmName.None), StringComparison.OrdinalIgnoreCase) &&
!String.IsNullOrEmpty(jwt.Signature))
{
throw new InvalidOperationException("Signature is not acceptable for algorithm None");
}
}
}
}

0 comments on commit 77b5186

Please sign in to comment.