init commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class EmbeddedSignature : SignatureSubpacket
|
||||
{
|
||||
public EmbeddedSignature(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.EmbeddedSignature, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class Exportable : SignatureSubpacket
|
||||
{
|
||||
private static byte[] BooleanToByteArray(bool val)
|
||||
{
|
||||
byte[] array = new byte[1];
|
||||
if (val)
|
||||
{
|
||||
array[0] = 1;
|
||||
return array;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public Exportable(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.Exportable, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public Exportable(bool critical, bool isExportable)
|
||||
: base(SignatureSubpacketTag.Exportable, critical, isLongLength: false, BooleanToByteArray(isExportable))
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsExportable()
|
||||
{
|
||||
return data[0] != 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class Features : SignatureSubpacket
|
||||
{
|
||||
public static readonly byte FEATURE_MODIFICATION_DETECTION = 1;
|
||||
|
||||
public bool SupportsModificationDetection => SupportsFeature(FEATURE_MODIFICATION_DETECTION);
|
||||
|
||||
private static byte[] FeatureToByteArray(byte feature)
|
||||
{
|
||||
return new byte[1] { feature };
|
||||
}
|
||||
|
||||
public Features(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.Features, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public Features(bool critical, byte feature)
|
||||
: base(SignatureSubpacketTag.Features, critical, isLongLength: false, FeatureToByteArray(feature))
|
||||
{
|
||||
}
|
||||
|
||||
public bool SupportsFeature(byte feature)
|
||||
{
|
||||
return Array.IndexOf((Array)data, (object?)feature) >= 0;
|
||||
}
|
||||
|
||||
private void SetSupportsFeature(byte feature, bool support)
|
||||
{
|
||||
if (feature == 0)
|
||||
{
|
||||
throw new ArgumentException("cannot be 0", "feature");
|
||||
}
|
||||
int num = Array.IndexOf((Array)data, (object?)feature);
|
||||
if (num >= 0 != support)
|
||||
{
|
||||
if (support)
|
||||
{
|
||||
data = Arrays.Append(data, feature);
|
||||
return;
|
||||
}
|
||||
byte[] array = new byte[data.Length - 1];
|
||||
Array.Copy(data, 0, array, 0, num);
|
||||
Array.Copy(data, num + 1, array, num, array.Length - num);
|
||||
data = array;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class IssuerKeyId : SignatureSubpacket
|
||||
{
|
||||
public long KeyId => ((long)(data[0] & 0xFF) << 56) | ((long)(data[1] & 0xFF) << 48) | ((long)(data[2] & 0xFF) << 40) | ((long)(data[3] & 0xFF) << 32) | ((long)(data[4] & 0xFF) << 24) | ((long)(data[5] & 0xFF) << 16) | ((long)(data[6] & 0xFF) << 8) | (long)((ulong)data[7] & 0xFFuL);
|
||||
|
||||
protected static byte[] KeyIdToBytes(long keyId)
|
||||
{
|
||||
return new byte[8]
|
||||
{
|
||||
(byte)(keyId >> 56),
|
||||
(byte)(keyId >> 48),
|
||||
(byte)(keyId >> 40),
|
||||
(byte)(keyId >> 32),
|
||||
(byte)(keyId >> 24),
|
||||
(byte)(keyId >> 16),
|
||||
(byte)(keyId >> 8),
|
||||
(byte)keyId
|
||||
};
|
||||
}
|
||||
|
||||
public IssuerKeyId(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.IssuerKeyId, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public IssuerKeyId(bool critical, long keyId)
|
||||
: base(SignatureSubpacketTag.IssuerKeyId, critical, isLongLength: false, KeyIdToBytes(keyId))
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class KeyExpirationTime : SignatureSubpacket
|
||||
{
|
||||
public long Time => ((long)(data[0] & 0xFF) << 24) | ((long)(data[1] & 0xFF) << 16) | ((long)(data[2] & 0xFF) << 8) | (long)((ulong)data[3] & 0xFFuL);
|
||||
|
||||
protected static byte[] TimeToBytes(long t)
|
||||
{
|
||||
return new byte[4]
|
||||
{
|
||||
(byte)(t >> 24),
|
||||
(byte)(t >> 16),
|
||||
(byte)(t >> 8),
|
||||
(byte)t
|
||||
};
|
||||
}
|
||||
|
||||
public KeyExpirationTime(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.KeyExpireTime, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public KeyExpirationTime(bool critical, long seconds)
|
||||
: base(SignatureSubpacketTag.KeyExpireTime, critical, isLongLength: false, TimeToBytes(seconds))
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class KeyFlags : SignatureSubpacket
|
||||
{
|
||||
public const int CertifyOther = 1;
|
||||
|
||||
public const int SignData = 2;
|
||||
|
||||
public const int EncryptComms = 4;
|
||||
|
||||
public const int EncryptStorage = 8;
|
||||
|
||||
public const int Split = 16;
|
||||
|
||||
public const int Authentication = 32;
|
||||
|
||||
public const int Shared = 128;
|
||||
|
||||
public int Flags
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = 0;
|
||||
for (int i = 0; i != data.Length; i++)
|
||||
{
|
||||
num |= (data[i] & 0xFF) << i * 8;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] IntToByteArray(int v)
|
||||
{
|
||||
byte[] array = new byte[4];
|
||||
int num = 0;
|
||||
for (int i = 0; i != 4; i++)
|
||||
{
|
||||
array[i] = (byte)(v >> i * 8);
|
||||
if (array[i] != 0)
|
||||
{
|
||||
num = i;
|
||||
}
|
||||
}
|
||||
byte[] array2 = new byte[num + 1];
|
||||
Array.Copy(array, 0, array2, 0, array2.Length);
|
||||
return array2;
|
||||
}
|
||||
|
||||
public KeyFlags(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.KeyFlags, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public KeyFlags(bool critical, int flags)
|
||||
: base(SignatureSubpacketTag.KeyFlags, critical, isLongLength: false, IntToByteArray(flags))
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class NotationData : SignatureSubpacket
|
||||
{
|
||||
public const int HeaderFlagLength = 4;
|
||||
|
||||
public const int HeaderNameLength = 2;
|
||||
|
||||
public const int HeaderValueLength = 2;
|
||||
|
||||
public bool IsHumanReadable => data[0] == 128;
|
||||
|
||||
public NotationData(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.NotationData, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public NotationData(bool critical, bool humanReadable, string notationName, string notationValue)
|
||||
: base(SignatureSubpacketTag.NotationData, critical, isLongLength: false, CreateData(humanReadable, notationName, notationValue))
|
||||
{
|
||||
}
|
||||
|
||||
private static byte[] CreateData(bool humanReadable, string notationName, string notationValue)
|
||||
{
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
memoryStream.WriteByte((byte)(humanReadable ? 128 : 0));
|
||||
memoryStream.WriteByte(0);
|
||||
memoryStream.WriteByte(0);
|
||||
memoryStream.WriteByte(0);
|
||||
byte[] array = null;
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(notationName);
|
||||
int num = System.Math.Min(bytes.Length, 255);
|
||||
array = Encoding.UTF8.GetBytes(notationValue);
|
||||
int num2 = System.Math.Min(array.Length, 255);
|
||||
memoryStream.WriteByte((byte)(num >> 8));
|
||||
memoryStream.WriteByte((byte)num);
|
||||
memoryStream.WriteByte((byte)(num2 >> 8));
|
||||
memoryStream.WriteByte((byte)num2);
|
||||
memoryStream.Write(bytes, 0, num);
|
||||
memoryStream.Write(array, 0, num2);
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
|
||||
public string GetNotationName()
|
||||
{
|
||||
int count = (data[4] << 8) + data[5];
|
||||
int index = 8;
|
||||
return Encoding.UTF8.GetString(data, index, count);
|
||||
}
|
||||
|
||||
public string GetNotationValue()
|
||||
{
|
||||
int num = (data[4] << 8) + data[5];
|
||||
int count = (data[6] << 8) + data[7];
|
||||
int index = 8 + num;
|
||||
return Encoding.UTF8.GetString(data, index, count);
|
||||
}
|
||||
|
||||
public byte[] GetNotationValueBytes()
|
||||
{
|
||||
int num = (data[4] << 8) + data[5];
|
||||
int num2 = (data[6] << 8) + data[7];
|
||||
int sourceIndex = 8 + num;
|
||||
byte[] array = new byte[num2];
|
||||
Array.Copy(data, sourceIndex, array, 0, num2);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class PreferredAlgorithms : SignatureSubpacket
|
||||
{
|
||||
private static byte[] IntToByteArray(int[] v)
|
||||
{
|
||||
byte[] array = new byte[v.Length];
|
||||
for (int i = 0; i != v.Length; i++)
|
||||
{
|
||||
array[i] = (byte)v[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public PreferredAlgorithms(SignatureSubpacketTag type, bool critical, bool isLongLength, byte[] data)
|
||||
: base(type, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public PreferredAlgorithms(SignatureSubpacketTag type, bool critical, int[] preferences)
|
||||
: base(type, critical, isLongLength: false, IntToByteArray(preferences))
|
||||
{
|
||||
}
|
||||
|
||||
public int[] GetPreferences()
|
||||
{
|
||||
int[] array = new int[data.Length];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = data[i] & 0xFF;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class PrimaryUserId : SignatureSubpacket
|
||||
{
|
||||
private static byte[] BooleanToByteArray(bool val)
|
||||
{
|
||||
byte[] array = new byte[1];
|
||||
if (val)
|
||||
{
|
||||
array[0] = 1;
|
||||
return array;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public PrimaryUserId(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.PrimaryUserId, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public PrimaryUserId(bool critical, bool isPrimaryUserId)
|
||||
: base(SignatureSubpacketTag.PrimaryUserId, critical, isLongLength: false, BooleanToByteArray(isPrimaryUserId))
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsPrimaryUserId()
|
||||
{
|
||||
return data[0] != 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class Revocable : SignatureSubpacket
|
||||
{
|
||||
private static byte[] BooleanToByteArray(bool value)
|
||||
{
|
||||
byte[] array = new byte[1];
|
||||
if (value)
|
||||
{
|
||||
array[0] = 1;
|
||||
return array;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public Revocable(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.Revocable, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public Revocable(bool critical, bool isRevocable)
|
||||
: base(SignatureSubpacketTag.Revocable, critical, isLongLength: false, BooleanToByteArray(isRevocable))
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsRevocable()
|
||||
{
|
||||
return data[0] != 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities.Date;
|
||||
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class SignatureCreationTime : SignatureSubpacket
|
||||
{
|
||||
protected static byte[] TimeToBytes(DateTime time)
|
||||
{
|
||||
long num = DateTimeUtilities.DateTimeToUnixMs(time) / 1000;
|
||||
return new byte[4]
|
||||
{
|
||||
(byte)(num >> 24),
|
||||
(byte)(num >> 16),
|
||||
(byte)(num >> 8),
|
||||
(byte)num
|
||||
};
|
||||
}
|
||||
|
||||
public SignatureCreationTime(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.CreationTime, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public SignatureCreationTime(bool critical, DateTime date)
|
||||
: base(SignatureSubpacketTag.CreationTime, critical, isLongLength: false, TimeToBytes(date))
|
||||
{
|
||||
}
|
||||
|
||||
public DateTime GetTime()
|
||||
{
|
||||
long num = (uint)((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]);
|
||||
return DateTimeUtilities.UnixMsToDateTime(num * 1000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class SignatureExpirationTime : SignatureSubpacket
|
||||
{
|
||||
public long Time => ((long)(data[0] & 0xFF) << 24) | ((long)(data[1] & 0xFF) << 16) | ((long)(data[2] & 0xFF) << 8) | (long)((ulong)data[3] & 0xFFuL);
|
||||
|
||||
protected static byte[] TimeToBytes(long t)
|
||||
{
|
||||
return new byte[4]
|
||||
{
|
||||
(byte)(t >> 24),
|
||||
(byte)(t >> 16),
|
||||
(byte)(t >> 8),
|
||||
(byte)t
|
||||
};
|
||||
}
|
||||
|
||||
public SignatureExpirationTime(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.ExpireTime, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public SignatureExpirationTime(bool critical, long seconds)
|
||||
: base(SignatureSubpacketTag.ExpireTime, critical, isLongLength: false, TimeToBytes(seconds))
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class SignerUserId : SignatureSubpacket
|
||||
{
|
||||
private static byte[] UserIdToBytes(string id)
|
||||
{
|
||||
byte[] array = new byte[id.Length];
|
||||
for (int i = 0; i != id.Length; i++)
|
||||
{
|
||||
array[i] = (byte)id[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public SignerUserId(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.SignerUserId, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public SignerUserId(bool critical, string userId)
|
||||
: base(SignatureSubpacketTag.SignerUserId, critical, isLongLength: false, UserIdToBytes(userId))
|
||||
{
|
||||
}
|
||||
|
||||
public string GetId()
|
||||
{
|
||||
char[] array = new char[data.Length];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = (char)(data[i] & 0xFF);
|
||||
}
|
||||
return new string(array);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Org.BouncyCastle.Bcpg.Sig;
|
||||
|
||||
public class TrustSignature : SignatureSubpacket
|
||||
{
|
||||
public int Depth => data[0] & 0xFF;
|
||||
|
||||
public int TrustAmount => data[1] & 0xFF;
|
||||
|
||||
private static byte[] IntToByteArray(int v1, int v2)
|
||||
{
|
||||
return new byte[2]
|
||||
{
|
||||
(byte)v1,
|
||||
(byte)v2
|
||||
};
|
||||
}
|
||||
|
||||
public TrustSignature(bool critical, bool isLongLength, byte[] data)
|
||||
: base(SignatureSubpacketTag.TrustSig, critical, isLongLength, data)
|
||||
{
|
||||
}
|
||||
|
||||
public TrustSignature(bool critical, int depth, int trustAmount)
|
||||
: base(SignatureSubpacketTag.TrustSig, critical, isLongLength: false, IntToByteArray(depth, trustAmount))
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user