blob: 2c0c314d968634d63bd638e3d0656213940a0306 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
}
}
}
|