< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Crypto.Hashes.Argon2Id
Assembly: NLightning.Infrastructure
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure/Crypto/Hashes/Argon2Id.cs
Tag: 30_15166811759
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 35
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
DeriveKeyFromPasswordAndSalt(...)0%2040%
Dispose()100%210%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure/Crypto/Hashes/Argon2Id.cs

#LineLine coverage
 1namespace NLightning.Infrastructure.Crypto.Hashes;
 2
 3using Domain.Crypto.Constants;
 4using Factories;
 5using Interfaces;
 6
 7public sealed class Argon2Id : IDisposable
 8{
 9    private const ulong DERIVE_KEY_MEM_LIMIT = 1 << 16; // 64 MiB
 10    private const ulong DERIVE_KEY_OPS_LIMIT = 3;
 11
 12    private readonly ICryptoProvider _cryptoProvider;
 13
 014    public Argon2Id()
 15    {
 016        _cryptoProvider = CryptoFactory.GetCryptoProvider();
 017    }
 18
 19    public void DeriveKeyFromPasswordAndSalt(string password, ReadOnlySpan<byte> salt, Span<byte> key)
 20    {
 021        if (key.Length != CryptoConstants.PRIVKEY_LEN)
 022            throw new ArgumentException($"Key must be {CryptoConstants.PRIVKEY_LEN} bytes long", nameof(key));
 23
 024        var ret = _cryptoProvider
 025            .DeriveKeyFromPasswordUsingArgon2I(key, password, salt, DERIVE_KEY_OPS_LIMIT, DERIVE_KEY_MEM_LIMIT);
 26
 027        if (ret != 0)
 028            throw new Exception("Argon2ID key derivation failed");
 029    }
 30
 31    public void Dispose()
 32    {
 033        _cryptoProvider.Dispose();
 034    }
 35}