From 35a5763d675a68ec5e36e05584481b49e1c41ce0 Mon Sep 17 00:00:00 2001 From: vnugent Date: Thu, 21 Dec 2023 21:08:42 -0500 Subject: final additions and updates before build --- .../src/MFA/UserMFAExtensions.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'plugins/VNLib.Plugins.Essentials.Accounts/src/MFA') diff --git a/plugins/VNLib.Plugins.Essentials.Accounts/src/MFA/UserMFAExtensions.cs b/plugins/VNLib.Plugins.Essentials.Accounts/src/MFA/UserMFAExtensions.cs index 3908613..9bf04c8 100644 --- a/plugins/VNLib.Plugins.Essentials.Accounts/src/MFA/UserMFAExtensions.cs +++ b/plugins/VNLib.Plugins.Essentials.Accounts/src/MFA/UserMFAExtensions.cs @@ -26,6 +26,7 @@ using System; using System.Linq; using System.Buffers; using System.Text.Json; +using System.Diagnostics; using System.Collections.Generic; using VNLib.Hashing; @@ -138,7 +139,7 @@ namespace VNLib.Plugins.Essentials.Accounts.MFA //Verify the TOTP using the decrypted secret isValid = count && VerifyTOTP(code, buffer.AsSpan(0, count), config.TOTPConfig); //Zero out the buffer - MemoryUtil.InitializeBlock(buffer.Span); + MemoryUtil.InitializeBlock(ref buffer.GetReference(), buffer.IntLength); } else { @@ -173,8 +174,9 @@ namespace VNLib.Plugins.Essentials.Accounts.MFA DateTimeOffset window = currentUtc.Add(config.TOTPPeriod.Multiply(currenStep)); //calculate the time step long timeStep = (long)Math.Floor(window.ToUnixTimeSeconds() / config.TOTPPeriod.TotalSeconds); - //try to compute the hash - _ = BitConverter.TryWriteBytes(stepBuffer, timeStep) ? 0 : throw new InternalBufferTooSmallException("Failed to format TOTP time step"); + //try to compute the hash, must always be storable in the buffer + bool writeResult = BitConverter.TryWriteBytes(stepBuffer, timeStep); + Debug.Assert(writeResult, "Failed to format the time step buffer because the buffer size was not large enough"); //If platform is little endian, reverse the byte order if (BitConverter.IsLittleEndian) { -- cgit