diff options
Diffstat (limited to 'lib/Plugins.Essentials/src')
4 files changed, 22 insertions, 32 deletions
diff --git a/lib/Plugins.Essentials/src/Accounts/PasswordHashing.cs b/lib/Plugins.Essentials/src/Accounts/PasswordHashing.cs index d80ee06..e6b9f24 100644 --- a/lib/Plugins.Essentials/src/Accounts/PasswordHashing.cs +++ b/lib/Plugins.Essentials/src/Accounts/PasswordHashing.cs @@ -184,7 +184,7 @@ namespace VNLib.Plugins.Essentials.Accounts } finally { - MemoryUtil.InitializeBlock(ref buffer.GetReference(),buffer.IntLength); + MemoryUtil.InitializeBlock(ref buffer.GetReference(), buffer.IntLength); } } @@ -214,7 +214,7 @@ namespace VNLib.Plugins.Essentials.Accounts } finally { - MemoryUtil.InitializeBlock(buffer.Span); + MemoryUtil.InitializeBlock(ref buffer.GetReference(), buffer.IntLength); } } @@ -242,7 +242,7 @@ namespace VNLib.Plugins.Essentials.Accounts finally { //Erase secret buffer - MemoryUtil.InitializeBlock(secretBuffer.Span); + MemoryUtil.InitializeBlock(ref secretBuffer.GetReference(), secretBuffer.IntLength); } } @@ -265,7 +265,7 @@ namespace VNLib.Plugins.Essentials.Accounts Argon2CostParams costParams = GetCostParams(); //Alloc heap buffer - using UnsafeMemoryHandle<byte> buffer = MemoryUtil.UnsafeAllocNearestPage<byte>(minBufferSize, true); + using UnsafeMemoryHandle<byte> buffer = MemoryUtil.UnsafeAllocNearestPage(minBufferSize, true); //Segment the buffer HashBufferSegments segments = new(buffer.Span, _secret.BufferSize, _config.SaltLen, (int)_config.HashLen); @@ -286,7 +286,7 @@ namespace VNLib.Plugins.Essentials.Accounts } finally { - MemoryUtil.InitializeBlock(buffer.Span); + MemoryUtil.InitializeBlock(ref buffer.GetReference(), buffer.IntLength); } } diff --git a/lib/Plugins.Essentials/src/Extensions/EssentialHttpEventExtensions.cs b/lib/Plugins.Essentials/src/Extensions/EssentialHttpEventExtensions.cs index b09924f..638b52a 100644 --- a/lib/Plugins.Essentials/src/Extensions/EssentialHttpEventExtensions.cs +++ b/lib/Plugins.Essentials/src/Extensions/EssentialHttpEventExtensions.cs @@ -908,7 +908,7 @@ namespace VNLib.Plugins.Essentials.Extensions entity.Server.Headers[HttpResponseHeader.Connection] = "Upgrade"; //Hash accept string - entity.Server.Headers["Sec-WebSocket-Accept"] = ManagedHash.ComputeBase64Hash($"{key.Trim()}{HttpHelpers.WebsocketRFC4122Guid}", HashAlg.SHA1); + entity.Server.Headers["Sec-WebSocket-Accept"] = ManagedHash.ComputeHash($"{key.Trim()}{HttpHelpers.WebsocketRFC4122Guid}", HashAlg.SHA1, HashEncodingMode.Base64); //Protocol if user specified it if (!string.IsNullOrWhiteSpace(subProtocol)) diff --git a/lib/Plugins.Essentials/src/Extensions/ICookieController.cs b/lib/Plugins.Essentials/src/Extensions/ICookieController.cs index b88e648..e14f710 100644 --- a/lib/Plugins.Essentials/src/Extensions/ICookieController.cs +++ b/lib/Plugins.Essentials/src/Extensions/ICookieController.cs @@ -22,6 +22,8 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ +using VNLib.Net.Http; + namespace VNLib.Plugins.Essentials.Extensions { /// <summary> @@ -34,14 +36,14 @@ namespace VNLib.Plugins.Essentials.Extensions /// </summary> /// <param name="entity">The http connection to set the cookie value for</param> /// <param name="value">The cookie value</param> - void SetCookie(HttpEntity entity, string value); + void SetCookie(IHttpEvent entity, string value); /// <summary> /// Gets the cookie value for the given entity /// </summary> /// <param name="entity">The entity to get the cookie for</param> /// <returns>The cookie value if set, null otherwise</returns> - string? GetCookie(HttpEntity entity); + string? GetCookie(IHttpEvent entity); /// <summary> /// Expires an existing request cookie for the given entity, avoiding @@ -49,6 +51,6 @@ namespace VNLib.Plugins.Essentials.Extensions /// </summary> /// <param name="entity">The http connection to expire the cookie on</param> /// <param name="force">Forcibly set the response cookie regardless of it's existence</param> - void ExpireCookie(HttpEntity entity, bool force); + void ExpireCookie(IHttpEvent entity, bool force); } }
\ No newline at end of file diff --git a/lib/Plugins.Essentials/src/Extensions/SingleCookieController.cs b/lib/Plugins.Essentials/src/Extensions/SingleCookieController.cs index 1893b6e..74d23f7 100644 --- a/lib/Plugins.Essentials/src/Extensions/SingleCookieController.cs +++ b/lib/Plugins.Essentials/src/Extensions/SingleCookieController.cs @@ -32,22 +32,10 @@ namespace VNLib.Plugins.Essentials.Extensions /// <summary> /// Implements a sinlge cookie controller /// </summary> - public class SingleCookieController : ICookieController + /// <param name="Name">The name of the cookie to manage</param> + /// <param name="ValidFor">The max-age cookie value</param> + public record class SingleCookieController(string Name, TimeSpan ValidFor) : ICookieController { - private readonly string _cookieName; - private readonly TimeSpan _validFor; - - /// <summary> - /// Creates a new <see cref="SingleCookieController"/> instance - /// </summary> - /// <param name="cookieName">The name of the cookie to manage</param> - /// <param name="validFor">The max-age cookie value</param> - public SingleCookieController(string cookieName, TimeSpan validFor) - { - _cookieName = cookieName; - _validFor = validFor; - } - /// <summary> /// The domain of the cookie /// </summary> @@ -78,40 +66,40 @@ namespace VNLib.Plugins.Essentials.Extensions /// Optionally clears the cookie (does not force) /// </summary> /// <param name="entity">The entity to clear the cookie for</param> - public void ExpireCookie(HttpEntity entity) => ExpireCookie(entity, false); + public void ExpireCookie(IHttpEvent entity) => ExpireCookie(entity, false); ///<inheritdoc/> - public void ExpireCookie(HttpEntity entity, bool force) + public void ExpireCookie(IHttpEvent entity, bool force) { _ = entity ?? throw new ArgumentNullException(nameof(entity)); SetCookieInternal(entity, string.Empty, force); } ///<inheritdoc/> - public string? GetCookie(HttpEntity entity) + public string? GetCookie(IHttpEvent entity) { _ = entity ?? throw new ArgumentNullException(nameof(entity)); - return entity.Server.RequestCookies.GetValueOrDefault(_cookieName); + return entity.Server.RequestCookies.GetValueOrDefault(Name); } ///<inheritdoc/> - public void SetCookie(HttpEntity entity, string value) + public void SetCookie(IHttpEvent entity, string value) { _ = entity ?? throw new ArgumentNullException(nameof(entity)); SetCookieInternal(entity, value, true); } - private void SetCookieInternal(HttpEntity entity, string value, bool force) + private void SetCookieInternal(IHttpEvent entity, string value, bool force) { //Only set cooke if already exists or force is true if (entity.Server.RequestCookies.ContainsKey(value) || force) { //Build and set cookie - HttpCookie cookie = new(_cookieName, value) + HttpCookie cookie = new(Name, value) { Secure = Secure, HttpOnly = HttpOnly, - ValidFor = _validFor, + ValidFor = ValidFor, SameSite = SameSite, Path = Path, Domain = Domain |