using System.Diagnostics.CodeAnalysis;

namespace DodoSSH.Crypto;

/// <summary>
/// A parsed view over an envelope's bytes.
/// </summary>
/// <remarks>
/// Holds no copies, so it must not outlive the buffer it was parsed from. Produced by
/// <see cref="DshEnvelope.TryRead"/>.
/// </remarks>
[SuppressMessage(
    "Performance",
    "CA1815:Override equals and object equals operator",
    Justification = "A ref struct over borrowed spans; equality is meaningless and cannot be expressed.")]
public readonly ref struct DshEnvelopeView
{
    internal DshEnvelopeView(
        CryptoSpec.AlgorithmId algorithm,
        ReadOnlySpan<byte> ephemeralPublicKey,
        ReadOnlySpan<byte> nonce,
        ReadOnlySpan<byte> ciphertext)
    {
        Algorithm = algorithm;
        EphemeralPublicKey = ephemeralPublicKey;
        Nonce = nonce;
        Ciphertext = ciphertext;
    }

    /// <summary>Construction the envelope declares.</summary>
    public CryptoSpec.AlgorithmId Algorithm { get; }

    /// <summary>Ephemeral X25519 public key, empty unless the algorithm carries one.</summary>
    public ReadOnlySpan<byte> EphemeralPublicKey { get; }

    /// <summary>Nonce.</summary>
    public ReadOnlySpan<byte> Nonce { get; }

    /// <summary>Ciphertext, including its trailing authentication tag.</summary>
    public ReadOnlySpan<byte> Ciphertext { get; }
}
