< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Jwt.JwtAlgorithmExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Jwt/JwtAlgorithmExtensions.cs
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 47
Line coverage: 100%
Branch coverage
100%
Covered branches: 19
Total branches: 19
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 09/08/2025 - 20:34:03 Line coverage: 100% (27/27) Branch coverage: 100% (19/19) Total lines: 106 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7211/19/2025 - 02:25:56 Line coverage: 100% (27/27) Branch coverage: 100% (19/19) Total lines: 47 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d 09/08/2025 - 20:34:03 Line coverage: 100% (27/27) Branch coverage: 100% (19/19) Total lines: 106 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7211/19/2025 - 02:25:56 Line coverage: 100% (27/27) Branch coverage: 100% (19/19) Total lines: 47 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToJwtString(...)100%1919100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Jwt/JwtAlgorithmExtensions.cs

#LineLine coverage
 1using Microsoft.IdentityModel.Tokens;
 2
 3namespace Kestrun.Jwt;
 4
 5/// <summary>
 6/// Provides extension methods for the JwtAlgorithm enum.
 7/// </summary>
 8public static class JwtAlgorithmExtensions
 9{
 10    /// <summary>
 11    /// Converts the specified <see cref="JwtAlgorithm"/> to its corresponding JWT algorithm string.
 12    /// </summary>
 13    /// <param name="alg">The JWT algorithm to convert.</param>
 14    /// <param name="keyByteLength">The key length in bytes, used only when <see cref="JwtAlgorithm.Auto"/> is specified
 15    /// <returns>The JWT algorithm string representation.</returns>
 16    public static string ToJwtString(this JwtAlgorithm alg, int keyByteLength = 0)
 17    {
 18        // handle the “Auto” case only for HMAC
 8019        return alg == JwtAlgorithm.Auto
 8020            ? keyByteLength switch
 8021            {
 822                >= 64 => SecurityAlgorithms.HmacSha512,
 723                >= 48 => SecurityAlgorithms.HmacSha384,
 2324                _ => SecurityAlgorithms.HmacSha256
 8025            }
 8026            : alg switch
 8027            {
 428                JwtAlgorithm.HS256 => SecurityAlgorithms.HmacSha256,
 329                JwtAlgorithm.HS384 => SecurityAlgorithms.HmacSha384,
 330                JwtAlgorithm.HS512 => SecurityAlgorithms.HmacSha512,
 8031
 632                JwtAlgorithm.RS256 => SecurityAlgorithms.RsaSha256,
 333                JwtAlgorithm.RS384 => SecurityAlgorithms.RsaSha384,
 334                JwtAlgorithm.RS512 => SecurityAlgorithms.RsaSha512,
 8035
 336                JwtAlgorithm.PS256 => SecurityAlgorithms.RsaSsaPssSha256,
 337                JwtAlgorithm.PS384 => SecurityAlgorithms.RsaSsaPssSha384,
 338                JwtAlgorithm.PS512 => SecurityAlgorithms.RsaSsaPssSha512,
 8039
 340                JwtAlgorithm.ES256 => SecurityAlgorithms.EcdsaSha256,
 341                JwtAlgorithm.ES384 => SecurityAlgorithms.EcdsaSha384,
 342                JwtAlgorithm.ES512 => SecurityAlgorithms.EcdsaSha512,
 8043
 244                _ => throw new ArgumentOutOfRangeException(nameof(alg), alg, null)
 8045            };
 46    }
 47}