using System.Buffers; using System.Runtime.InteropServices; using System.Security.Cryptography; namespace Shared; public static class Extensions { public static string Hex(this Span span) { return span.ToArray().Hex(); } public static string Hex(this IEnumerable array) { return string.Join(' ', array.ToArray().Select(x => x.ToString("X2"))); } public static unsafe byte* Ptr(this Span span) { fixed (byte* data = span) { return data; } } public static string TrimNullTerm(this string text) { return text.Split('\0').FirstOrDefault() ?? ""; } public static IMemoryOwner RentZero(this MemoryPool pool, int minSize) { IMemoryOwner owner = pool.Rent(minSize); CryptographicOperations.ZeroMemory(owner.Memory.Span); return owner; } }