summary refs log tree commit diff
path: root/crypto/src/util/Arrays.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-07-23 16:53:51 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-07-23 16:53:51 +0700
commite5db546809a6485a82427c105c1d4f3a3b25fa5a (patch)
tree94e4823bc84bb04c366c296e24409b1dc817bc4c /crypto/src/util/Arrays.cs
parentAdd automatic EC point validation for decoded points and for multiplier outputs (diff)
downloadBouncyCastle.NET-ed25519-e5db546809a6485a82427c105c1d4f3a3b25fa5a.tar.xz
Port of new TlsEccUtilities class from Java
Various support methods in TlsUtilities and Arrays
Fix short->byte for several enumeration types
Diffstat (limited to '')
-rw-r--r--crypto/src/util/Arrays.cs102
1 files changed, 102 insertions, 0 deletions
diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs
index 37da3940f..e629fcf65 100644
--- a/crypto/src/util/Arrays.cs
+++ b/crypto/src/util/Arrays.cs
@@ -366,6 +366,36 @@ namespace Org.BouncyCastle.Utilities
             return existing;
         }
 
+        public static bool Contains(byte[] a, byte n)
+        {
+            for (int i = 0; i < a.Length; ++i)
+            {
+                if (a[i] == n)
+                    return true;
+            }
+            return false;
+        }
+
+        public static bool Contains(short[] a, short n)
+        {
+            for (int i = 0; i < a.Length; ++i)
+            {
+                if (a[i] == n)
+                    return true;
+            }
+            return false;
+        }
+
+        public static bool Contains(int[] a, int n)
+        {
+            for (int i = 0; i < a.Length; ++i)
+            {
+                if (a[i] == n)
+                    return true;
+            }
+            return false;
+        }
+
         public static void Fill(
             byte[]	buf,
             byte	b)
@@ -384,6 +414,42 @@ namespace Org.BouncyCastle.Utilities
             return result;
         }
 
+        public static byte[] Append(byte[] a, byte b)
+        {
+            if (a == null)
+                return new byte[] { b };
+
+            int length = a.Length;
+            byte[] result = new byte[length + 1];
+            Array.Copy(a, 0, result, 0, length);
+            result[length] = b;
+            return result;
+        }
+
+        public static short[] Append(short[] a, short b)
+        {
+            if (a == null)
+                return new short[] { b };
+
+            int length = a.Length;
+            short[] result = new short[length + 1];
+            Array.Copy(a, 0, result, 0, length);
+            result[length] = b;
+            return result;
+        }
+
+        public static int[] Append(int[] a, int b)
+        {
+            if (a == null)
+                return new int[] { b };
+
+            int length = a.Length;
+            int[] result = new int[length + 1];
+            Array.Copy(a, 0, result, 0, length);
+            result[length] = b;
+            return result;
+        }
+
         public static byte[] Concatenate(byte[] a, byte[] b)
         {
             if (a == null)
@@ -397,6 +463,42 @@ namespace Org.BouncyCastle.Utilities
             return rv;
         }
 
+        public static byte[] Prepend(byte[] a, byte b)
+        {
+            if (a == null)
+                return new byte[] { b };
+
+            int length = a.Length;
+            byte[] result = new byte[length + 1];
+            Array.Copy(a, 0, result, 1, length);
+            result[0] = b;
+            return result;
+        }
+
+        public static short[] Prepend(short[] a, short b)
+        {
+            if (a == null)
+                return new short[] { b };
+
+            int length = a.Length;
+            short[] result = new short[length + 1];
+            Array.Copy(a, 0, result, 1, length);
+            result[0] = b;
+            return result;
+        }
+
+        public static int[] Prepend(int[] a, int b)
+        {
+            if (a == null)
+                return new int[] { b };
+
+            int length = a.Length;
+            int[] result = new int[length + 1];
+            Array.Copy(a, 0, result, 1, length);
+            result[0] = b;
+            return result;
+        }
+
         public static byte[] Reverse(byte[] a)
         {
             if (a == null)