< 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
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 28
Line coverage: 100%
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%11100%
Parse(...)100%11100%

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    {
 414        var hexIdentifier = Convert.ToHexString(Encoding.UTF8.GetBytes(clientId));
 415        var id = Guid.NewGuid().ToString("D");
 416        return $"{hexIdentifier}-{id}";
 17    }
 18
 19    /// <inheritdoc />
 20    public string Parse(string apiKey)
 21    {
 322        var firstSeparatorIndex = apiKey.IndexOf('-');
 323        var hexIdentifier = apiKey[..firstSeparatorIndex];
 324        var clientId = Encoding.UTF8.GetString(Convert.FromHexString(hexIdentifier));
 25
 326        return clientId;
 27    }
 28}