< 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@0d738bf294e6281b936d031e1979d928007495ff
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 08/26/2025 - 14:53:17 Line coverage: 100% (27/27) Branch coverage: 100% (19/19) Total lines: 106 Tag: Kestrun/Kestrun@78d1e497d8ba989d121b57aa39aa3c6b22de743111/19/2025 - 02:25:56 Line coverage: 100% (27/27) Branch coverage: 100% (19/19) Total lines: 47 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d 08/26/2025 - 14:53:17 Line coverage: 100% (27/27) Branch coverage: 100% (19/19) Total lines: 106 Tag: Kestrun/Kestrun@78d1e497d8ba989d121b57aa39aa3c6b22de743111/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
 7619        return alg == JwtAlgorithm.Auto
 7620            ? keyByteLength switch
 7621            {
 822                >= 64 => SecurityAlgorithms.HmacSha512,
 723                >= 48 => SecurityAlgorithms.HmacSha384,
 2124                _ => SecurityAlgorithms.HmacSha256
 7625            }
 7626            : alg switch
 7627            {
 328                JwtAlgorithm.HS256 => SecurityAlgorithms.HmacSha256,
 329                JwtAlgorithm.HS384 => SecurityAlgorithms.HmacSha384,
 330                JwtAlgorithm.HS512 => SecurityAlgorithms.HmacSha512,
 7631
 532                JwtAlgorithm.RS256 => SecurityAlgorithms.RsaSha256,
 333                JwtAlgorithm.RS384 => SecurityAlgorithms.RsaSha384,
 334                JwtAlgorithm.RS512 => SecurityAlgorithms.RsaSha512,
 7635
 336                JwtAlgorithm.PS256 => SecurityAlgorithms.RsaSsaPssSha256,
 337                JwtAlgorithm.PS384 => SecurityAlgorithms.RsaSsaPssSha384,
 338                JwtAlgorithm.PS512 => SecurityAlgorithms.RsaSsaPssSha512,
 7639
 340                JwtAlgorithm.ES256 => SecurityAlgorithms.EcdsaSha256,
 341                JwtAlgorithm.ES384 => SecurityAlgorithms.EcdsaSha384,
 342                JwtAlgorithm.ES512 => SecurityAlgorithms.EcdsaSha512,
 7643
 244                _ => throw new ArgumentOutOfRangeException(nameof(alg), alg, null)
 7645            };
 46    }
 47}