using System.Runtime.InteropServices;
using ProtonVPN.OperatingSystems.WebAuthn.Enums;
using ProtonVPN.OperatingSystems.WebAuthn.Interop.Marshalers;
using ProtonVPN.OperatingSystems.WebAuthn.Interop.StructVersions;
namespace ProtonVPN.OperatingSystems.WebAuthn.Interop.Structs.GetAssertion;
///
/// Assertion
///
/// Corresponds to WEBAUTHN_ASSERTION.
[StructLayout(LayoutKind.Sequential)]
public sealed class Assertion
{
///
/// // Version of this structure, to allow for modifications in the future.
///
public AssertionVersion Version { get; private set; }
///
/// The size of the authenticator data.
///
private int _authenticatorDataLength;
///
/// A pointer to the authenticator data.
///
private ByteArrayOut _authenticatorData;
///
/// The size of the signature that was generated for this assertion.
///
private int _signatureLength;
///
/// A pointer to the signature that was generated for this assertion.
///
private ByteArrayOut _signature;
///
/// The credential that was used for this assertion.
///
public CredentialOut Credential { get; private set; }
///
/// The size of the user Id.
///
private int _userIdLength;
///
/// A pointer to the user Id.
///
private ByteArrayOut _userId;
///
/// A CBOR map from extension identifiers to their authenticator extension inputs,
/// created by the client based on the extensions requested by the Relying Party, if any.
///
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_2.
public ExtensionsOut Extensions { get; private set; }
///
/// Size of the Large Blob
///
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_2.
private int _largeBlobLength;
///
/// A pointer to the credential blob.
///
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_2.
private ByteArrayOut _largeBlob;
///
/// Status of the credential blob.
///
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_2.
public CredentialLargeBlobStatus LargeBlobStatus { get; private set; }
///
/// A salt used to generate the HMAC secret.
///
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_3.
private nint _hmacSecret;
///
/// The transport that was used.
///
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_4.
public AuthenticatorTransport UsedTransport { get; private set; }
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_5.
private int _unsignedExtensionOutputsLength;
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_5.
private ByteArrayOut _unsignedExtensionOutputs;
///
/// Authenticator data that was created for this assertion.
///
public byte[] AuthenticatorData => _authenticatorData?.Read(_authenticatorDataLength);
///
/// Signature that was generated for this assertion.
///
public byte[] Signature => _signature?.Read(_signatureLength);
///
/// User Identifier
///
public byte[] UserId => _userId?.Read(_userIdLength);
///
/// Credential Large Blob
///
public byte[] LargeBlob => _largeBlob?.Read(_largeBlobLength);
///
/// Unsigned extension outputs.
///
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_5.
public byte[] UnsignedExtensionOutputs => _unsignedExtensionOutputs?.Read(_unsignedExtensionOutputsLength);
///
/// A salt used to generate the HMAC secret.
///
/// This field has been added in WEBAUTHN_ASSERTION_VERSION_3.
public HmacSecretSaltOut HmacSecret
{
get
{
if (_hmacSecret == nint.Zero)
{
return null;
}
return Marshal.PtrToStructure(_hmacSecret);
}
}
}