summary refs log tree commit diff
path: root/crypto/src/bcpg/sig/Utilities.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/bcpg/sig/Utilities.cs')
-rw-r--r--crypto/src/bcpg/sig/Utilities.cs41
1 files changed, 41 insertions, 0 deletions
diff --git a/crypto/src/bcpg/sig/Utilities.cs b/crypto/src/bcpg/sig/Utilities.cs
new file mode 100644
index 000000000..2c0c314d9
--- /dev/null
+++ b/crypto/src/bcpg/sig/Utilities.cs
@@ -0,0 +1,41 @@
+using System;
+
+using Org.BouncyCastle.Crypto.Utilities;
+
+namespace Org.BouncyCastle.Bcpg.Sig
+{
+    internal static class Utilities
+    {
+        internal static bool BooleanFromBytes(byte[] bytes)
+        {
+            if (bytes.Length != 1)
+                throw new InvalidOperationException("Byte array has unexpected length. Expected length 1, got " + bytes.Length);
+
+            if (bytes[0] == 0)
+                return false;
+
+            if (bytes[0] == 1)
+                return true;
+
+            throw new InvalidOperationException("Unexpected byte value for boolean encoding: " + bytes[0]);
+        }
+
+        internal static byte[] BooleanToBytes(bool value)
+        {
+            return new byte[1]{ Convert.ToByte(value) };
+        }
+
+        internal static uint TimeFromBytes(byte[] bytes)
+        {
+            if (bytes.Length != 4)
+                throw new InvalidOperationException("Byte array has unexpected length. Expected length 4, got " + bytes.Length);
+
+            return Pack.BE_To_UInt32(bytes);
+        }
+
+        internal static byte[] TimeToBytes(uint t)
+        {
+            return Pack.UInt32_To_BE(t);
+        }
+    }
+}