< Summary

Information
Class: ArturRios.Util.Hashing.HashConfiguration
Assembly: ArturRios.Util
File(s): /home/runner/work/dotnet-util/dotnet-util/src/Hashing/HashConfiguration.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 65
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 5
Fully covered methods: 5
Total methods: 5
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_DegreeOfParallelism()100%11100%
get_NumberOfIterations()100%11100%
get_MemoryToUseInKb()100%11100%
Positive(...)100%11100%

File(s)

/home/runner/work/dotnet-util/dotnet-util/src/Hashing/HashConfiguration.cs

#LineLine coverage
 1namespace ArturRios.Util.Hashing;
 2
 3/// <summary>
 4/// Configuration values for controlling Argon2id hashing cost parameters.
 5/// </summary>
 6/// <remarks>
 7/// The defaults are deliberately expensive: a single hash reserves
 8/// <see cref="DefaultMemoryToUseInKb"/> kilobytes (roughly 600 MB) across
 9/// <see cref="DefaultDegreeOfParallelism"/> lanes. That is appropriate for a login path that runs rarely,
 10/// but a server hashing many secrets concurrently will exhaust its memory long before its CPU, so size the
 11/// parameters against the expected concurrency. Note that changing them invalidates existing hashes:
 12/// a stored hash can only be verified with the configuration it was produced with.
 13/// </remarks>
 14/// <param name="degreeOfParallelism">Number of threads (lanes) to use; defaults to <see cref="DefaultDegreeOfParallelis
 15/// <param name="numberOfIterations">Number of iterations; defaults to <see cref="DefaultNumberOfIterations"/>.</param>
 16/// <param name="memoryToUseInKb">Memory size in kilobytes; defaults to <see cref="DefaultMemoryToUseInKb"/>.</param>
 17/// <exception cref="ArgumentOutOfRangeException">Any supplied value is less than one.</exception>
 3118public class HashConfiguration(
 3119    int? degreeOfParallelism = null,
 3120    int? numberOfIterations = null,
 3121    int? memoryToUseInKb = null)
 22{
 23    /// <summary>
 24    /// Default parallelism (threads) used when unspecified.
 25    /// </summary>
 26    public const int DefaultDegreeOfParallelism = 16;
 27
 28    /// <summary>
 29    /// Default recommended minimum iteration count.
 30    /// </summary>
 31    public const int DefaultNumberOfIterations = 4;
 32
 33    /// <summary>
 34    /// Default memory cost (600 MB) expressed in kilobytes.
 35    /// </summary>
 36    public const int DefaultMemoryToUseInKb = 600000;
 37
 38    /// <summary>
 39    /// Gets the configured degree of parallelism.
 40    /// </summary>
 2141    public int DegreeOfParallelism { get; } =
 3742        Positive(degreeOfParallelism ?? DefaultDegreeOfParallelism, nameof(degreeOfParallelism));
 43
 44    /// <summary>
 45    /// Gets the configured number of iterations.
 46    /// </summary>
 2147    public int NumberOfIterations { get; } =
 3548        Positive(numberOfIterations ?? DefaultNumberOfIterations, nameof(numberOfIterations));
 49
 50    /// <summary>
 51    /// Gets the configured memory usage in kilobytes.
 52    /// </summary>
 2153    public int MemoryToUseInKb { get; } =
 3354        Positive(memoryToUseInKb ?? DefaultMemoryToUseInKb, nameof(memoryToUseInKb));
 55
 56    /// <summary>
 57    /// Rejects cost parameters Argon2 cannot honour.
 58    /// </summary>
 59    private static int Positive(int value, string parameterName)
 60    {
 10561        ArgumentOutOfRangeException.ThrowIfLessThan(value, 1, parameterName);
 62
 9963        return value;
 64    }
 65}