using System.Runtime.InteropServices;
namespace ProtonVPN.OperatingSystems.WebAuthn.Interop.Structs;
///
/// The structure that contains the SALT values for the HMAC secret.
///
/// Corresponds to WEBAUTHN_HMAC_SECRET_SALT_VALUES.
[StructLayout(LayoutKind.Sequential)]
public class HmacSecretSaltValuesIn : IDisposable
{
///
/// The global HMAC SALT.
///
private nint _globalHmacSalt;
///
/// List of credentials with HMAC secret SALT.
///
private CredentialsWithHmacSecretSaltIn _credWithHmacSecretSaltList;
public HmacSecretSaltValuesIn(HmacSecretSaltIn globalHmacSalt, CredentialWithHmacSecretSaltIn[] credsWithHmacSecretSalt)
{
if (globalHmacSalt != null)
{
_globalHmacSalt = Marshal.AllocHGlobal(Marshal.SizeOf());
Marshal.StructureToPtr(globalHmacSalt, _globalHmacSalt, false);
}
_credWithHmacSecretSaltList = new CredentialsWithHmacSecretSaltIn(credsWithHmacSecretSalt);
}
public bool HasGlobalHmacSalt => _globalHmacSalt != nint.Zero;
public void Dispose()
{
if (_globalHmacSalt != nint.Zero)
{
Marshal.FreeHGlobal(_globalHmacSalt);
_globalHmacSalt = nint.Zero;
}
_credWithHmacSecretSaltList?.Dispose();
_credWithHmacSecretSaltList = null;
}
}