TrimArray() simplification
[NovacoinLibrary.git] / Novacoin / Interop.cs
index 0cb7e75..54768cf 100644 (file)
@@ -18,6 +18,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Text;
 
 namespace Novacoin
@@ -82,6 +83,25 @@ namespace Novacoin
             return bytes;
         }
 
+        public static byte[] TrimArray(byte[] bytes)
+        {
+            int trimStart = bytes.Length - 1;
+            while (trimStart >= 0 && bytes[trimStart] == 0)
+            {
+                trimStart--;
+            }
+
+            return bytes.Take(trimStart + 1).ToArray();
+        }
+
+        public static byte[] AppendWithZeros(byte[] bytes, int nTargetLen=32)
+        {
+            var result = new byte[nTargetLen];
+            bytes.CopyTo(result, 0);
+
+            return result;
+        }
+
         public static string ToHex(byte[] bytes)
         {
             var sb = new StringBuilder();