Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

2.3 KB
Raw Blame
// <auto-generated />
// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.

#nullable enable

namespace AliasVault.Shared.Models.Enums;

/// <summary>
/// The algorithms an account signing keypair can sign with.
/// The token is the only persisted and transmitted identifier; the ordinals below are cosmetic.
/// </summary>
public enum SigningKeyAlgorithm
{
    /// <summary>
    /// Ed25519 (RFC 8032), verified strictly.
    /// </summary>
    Ed25519 = 0,
}

/// <summary>
/// Token conversions for <see cref="SigningKeyAlgorithm"/>.
/// </summary>
public static class SigningKeyAlgorithms
{
    /// <summary>
    /// Returns the wire/storage token for a SigningKeyAlgorithm.
    /// </summary>
    /// <param name="type">The SigningKeyAlgorithm to convert.</param>
    /// <returns>The token.</returns>
    public static string ToToken(SigningKeyAlgorithm type) => type switch
    {
        SigningKeyAlgorithm.Ed25519 => "ed25519",
        _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown SigningKeyAlgorithm."),
    };

    /// <summary>
    /// Parses a token.
    /// </summary>
    /// <param name="token">The token to parse.</param>
    /// <param name="type">The parsed SigningKeyAlgorithm.</param>
    /// <returns>True when the token names a SigningKeyAlgorithm this build supports.</returns>
    public static bool TryParse(string? token, out SigningKeyAlgorithm type)
    {
        switch (token)
        {
            case "ed25519":
                type = SigningKeyAlgorithm.Ed25519;
                return true;
            default:
                type = default;
                return false;
        }
    }

    /// <summary>
    /// Parses a token and returns the SigningKeyAlgorithm.
    /// </summary>
    /// <param name="token">The token to parse.</param>
    /// <returns>The parsed SigningKeyAlgorithm.</returns>
    public static SigningKeyAlgorithm Parse(string? token)
    {
        if (!TryParse(token, out var type))
        {
            throw new ArgumentOutOfRangeException(nameof(token), token, "Unknown SigningKeyAlgorithm token.");
        }

        return type;
    }
}