summary refs log tree commit diff
path: root/crypto/src/util
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-02-27 20:00:46 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-27 20:00:46 +0700
commitca24841d2e00c51a0a52df522139fcb096e0995f (patch)
treeea5d86bd2127a80ecc64a0b44f8b114f67291aef /crypto/src/util
parentBcpg: update signature subpackets (diff)
downloadBouncyCastle.NET-ed25519-ca24841d2e00c51a0a52df522139fcb096e0995f.tar.xz
Use string.Create when available
Diffstat (limited to 'crypto/src/util')
-rw-r--r--crypto/src/util/Strings.cs10
1 files changed, 10 insertions, 0 deletions
diff --git a/crypto/src/util/Strings.cs b/crypto/src/util/Strings.cs
index b1a63a3a1..147b6d349 100644
--- a/crypto/src/util/Strings.cs
+++ b/crypto/src/util/Strings.cs
@@ -18,12 +18,22 @@ namespace Org.BouncyCastle.Utilities
 
         public static string FromByteArray(byte[] bs)
         {
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+            return string.Create(bs.Length, bs, (chars, bytes) =>
+            {
+                for (int i = 0; i < chars.Length; ++i)
+                {
+                    chars[i] = Convert.ToChar(bytes[i]);
+                }
+            });
+#else
             char[] cs = new char[bs.Length];
             for (int i = 0; i < cs.Length; ++i)
             {
                 cs[i] = Convert.ToChar(bs[i]);
             }
             return new string(cs);
+#endif
         }
 
         public static byte[] ToByteArray(char[] cs)