From d27516ac011e8434e3ea1218b9d6d3b5237e6995 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 22 Oct 2022 22:51:55 +0100 Subject: [PATCH] cosmetics --- OpenSim/Framework/Console/LocalConsole.cs | 15 +++-- OpenSim/Framework/Util.cs | 63 ++++++++++++++----- .../Shared/Api/Implementation/LSL_Api.cs | 12 ++-- .../Shared/Api/Implementation/OSSL_Api.cs | 9 +-- 4 files changed, 68 insertions(+), 31 deletions(-) diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs index 291e2e6afd..d5c55f1c4c 100755 --- a/OpenSim/Framework/Console/LocalConsole.cs +++ b/OpenSim/Framework/Console/LocalConsole.cs @@ -324,10 +324,8 @@ namespace OpenSim.Framework.Console m_cursorYPosition = SetCursorZeroLeft(m_cursorYPosition); int count = m_commandLine.Length + prompt.Length; - char[] spaces = new char[count]; - for(int i = 0; i < spaces.Length; i++) - spaces[i] = ' '; - System.Console.Write(spaces); + if(count > 0) + System.Console.Write(new string(' ', count)); m_cursorYPosition = SetCursorZeroLeft(m_cursorYPosition); } @@ -444,11 +442,12 @@ namespace OpenSim.Framework.Console m_cursorYPosition = SetCursorZeroLeft(m_cursorYPosition); int count = m_commandLine.Length + prompt.Length - text.Length; - WriteLocalText(text, level); - for (int i = 0; i < count; ++i) - System.Console.Write(" "); - System.Console.WriteLine(); + if(count > 0) + System.Console.WriteLine(new string(' ', count)); + else + System.Console.WriteLine(); + m_cursorYPosition = System.Console.CursorTop; Show(); } diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index aca0edf77e..8e38f13f54 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -1230,31 +1230,66 @@ namespace OpenSim.Framework return (char)(b > 9 ? b + 0x37 : b + '0'); } - public static string bytesToHexString(Span bytes, bool lowerCaps) + public static unsafe string bytesToHexString(byte[] bytes, bool lowerCaps) { if (bytes == null || bytes.Length == 0) return string.Empty; - Span chars = stackalloc char[2 * bytes.Length]; - if (lowerCaps) + return string.Create(2 * bytes.Length, bytes, (chars, bytes) => { + fixed (char* dstb = chars) + fixed (byte* srcb = bytes) + { + char* dst = dstb; + if (lowerCaps) + { + for (int i = 0; i < bytes.Length; ++i) + { + byte b = srcb[i]; + *dst++ = HighNibbleToHexByteCharLowcaps(b); + *dst++ = LowNibbleToHexByteCharLowcaps(b); + } + } + else + { + for (int i = 0; i < bytes.Length; ++i) + { + byte b = srcb[i]; + *dst++ = HighNibbleToHexByteCharLowcaps(b); + *dst++ = LowNibbleToHexByteCharLowcaps(b); + } + } + } + }); + } + + public static unsafe string bytesToLowcaseHexString(byte[] bytes) + { + if (bytes == null || bytes.Length == 0) + return string.Empty; + + return string.Create(2 * bytes.Length, bytes, (chars, bytes) => + { + fixed (char* dstb = chars) + fixed (byte* srcb = bytes) + { + char* dst = dstb; + for (int i = 0; i < bytes.Length; ++i) + { + byte b = srcb[i]; + *dst++ = HighNibbleToHexByteCharLowcaps(b); + *dst++ = LowNibbleToHexByteCharLowcaps(b); + } + } + /* for (int i = 0, j = 0; i < bytes.Length; ++i) { byte b = bytes[i]; chars[j++] = HighNibbleToHexByteCharLowcaps(b); chars[j++] = LowNibbleToHexByteCharLowcaps(b); } - } - else - { - for (int i = 0, j = 0; i < bytes.Length; ++i) - { - byte b = bytes[i]; - chars[j++] = HighNibbleToHexByteCharHighcaps(b); - chars[j++] = LowNibbleToHexByteCharHighcaps(b); - } - } - return new string(chars); + */ + }); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 75be16f284..a9f523ce6d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -8231,12 +8231,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_String llSHA256String(LSL_String input) { + byte[] bytes; // Create a SHA256 - using SHA256 sha256Hash = SHA256.Create(); - - // ComputeHash - returns byte array - Span bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input)).AsSpan(); - return Util.bytesToHexString(bytes, true); + using (SHA256 sha256Hash = SHA256.Create()) + { + // ComputeHash - returns byte array + bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input.m_string)); + } + return Util.bytesToLowcaseHexString(bytes); } protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index ce8351d869..b5b7faa148 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2619,13 +2619,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public string osSHA256(string input) { + byte[] bytes; // Create a SHA256 - using (SHA256 sha256Hash = SHA256.Create()) - { + using (SHA256 sha256Hash = SHA256.Create()) + { // ComputeHash - returns byte array - Span bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input)).AsSpan(); - return Util.bytesToHexString(bytes, true); + bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); } + return Util.bytesToLowcaseHexString(bytes); } ///