Features.cs
1.99 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Bcpg.Sig
{
/**
* packet giving signature expiration time.
*/
public class Features
: SignatureSubpacket
{
/** Identifier for the modification detection feature */
public static readonly byte FEATURE_MODIFICATION_DETECTION = 1;
private static byte[] FeatureToByteArray(byte feature)
{
return new byte[]{ 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, false, FeatureToByteArray(feature))
{
}
/**
* Returns if modification detection is supported.
*/
public bool SupportsModificationDetection
{
get { return SupportsFeature(FEATURE_MODIFICATION_DETECTION); }
}
/**
* Returns if a particular feature is supported.
*/
public bool SupportsFeature(byte feature)
{
return Array.IndexOf(data, feature) >= 0;
}
/**
* Sets support for a particular feature.
*/
private void SetSupportsFeature(byte feature, bool support)
{
if (feature == 0)
throw new ArgumentException("cannot be 0", "feature");
int i = Array.IndexOf(data, feature);
if ((i >= 0) == support)
return;
if (support)
{
data = Arrays.Append(data, feature);
}
else
{
byte[] temp = new byte[data.Length - 1];
Array.Copy(data, 0, temp, 0, i);
Array.Copy(data, i + 1, temp, i, temp.Length - i);
data = temp;
}
}
}
}