< Summary

Information
Class: Elsa.Identity.Services.DefaultApiKeyGeneratorAndParser
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/DefaultApiKeyGeneratorAndParser.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 7
Coverable lines: 7
Total lines: 28
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
Generate(...)100%210%
Parse(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/DefaultApiKeyGeneratorAndParser.cs

#LineLine coverage
 1using System.Text;
 2using Elsa.Identity.Contracts;
 3
 4namespace Elsa.Identity.Services;
 5
 6/// <summary>
 7/// Generates and parses API keys.
 8/// </summary>
 9public class DefaultApiKeyGeneratorAndParser : IApiKeyGenerator, IApiKeyParser
 10{
 11    /// <inheritdoc />
 12    public string Generate(string clientId)
 13    {
 014        var hexIdentifier = Convert.ToHexString(Encoding.UTF8.GetBytes(clientId));
 015        var id = Guid.NewGuid().ToString("D");
 016        return $"{hexIdentifier}-{id}";
 17    }
 18
 19    /// <inheritdoc />
 20    public string Parse(string apiKey)
 21    {
 022        var firstSeparatorIndex = apiKey.IndexOf('-');
 023        var hexIdentifier = apiKey[..firstSeparatorIndex];
 024        var clientId = Encoding.UTF8.GetString(Convert.FromHexString(hexIdentifier));
 25
 026        return clientId;
 27    }
 28}