< Summary

Information
Class: Elsa.Identity.Models.HashedSecret
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Models/HashedSecret.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 7
Coverable lines: 7
Total lines: 40
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Secret()100%210%
FromBytes(...)100%210%
FromString(...)100%210%
EncodeSecret()100%210%
EncodeSalt()100%210%
Decode(...)100%210%
Encode(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Models/HashedSecret.cs

#LineLine coverage
 1namespace Elsa.Identity.Models;
 2
 3/// <summary>
 4/// Represents a hashed secret.
 5/// </summary>
 6/// <param name="Secret">A base64 encoded string representing the hashed secret.</param>
 7/// <param name="Salt">A base64 encoded string representing the salt.</param>
 08public record HashedSecret(byte[] Secret, byte[] Salt)
 9{
 10    /// <summary>
 11    /// Creates a new instance of <see cref="HashedSecret"/> from a byte array representing the hashed secret and the sa
 12    /// </summary>
 13    /// <param name="secret">The hashed secret.</param>
 14    /// <param name="salt">The salt.</param>
 15    /// <returns>A new instance of <see cref="HashedSecret"/>.</returns>
 016    public static HashedSecret FromBytes(byte[] secret, byte[] salt) => new(secret, salt);
 17
 18    /// <summary>
 19    /// Creates a new instance of <see cref="HashedSecret"/> from a string representing the hashed secret and the salt.
 20    /// </summary>
 21    /// <param name="secret">The hashed secret.</param>
 22    /// <param name="salt">The salt.</param>
 23    /// <returns>A new instance of <see cref="HashedSecret"/>.</returns>
 024    public static HashedSecret FromString(string secret, string salt) => new(Decode(secret), Decode(salt));
 25
 26    /// <summary>
 27    /// Encodes the secret using base64.
 28    /// </summary>
 29    /// <returns>The base64-encoded secret.</returns>
 030    public string EncodeSecret() => Encode(Secret);
 31
 32    /// <summary>
 33    /// Encodes the salt using base64.
 34    /// </summary>
 35    /// <returns>The base64-encoded salt.</returns>
 036    public string EncodeSalt() => Encode(Salt);
 37
 038    private static byte[] Decode(string value) => Convert.FromBase64String(value);
 039    private static string Encode(byte[] value) => Convert.ToBase64String(value);
 40}