KeyFlags.cs
1.53 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.Math;
namespace Org.BouncyCastle.Bcpg.Sig
{
/**
* Packet holding the key flag values.
*/
public class KeyFlags
: SignatureSubpacket
{
public const int CertifyOther = 0x01;
public const int SignData = 0x02;
public const int EncryptComms = 0x04;
public const int EncryptStorage = 0x08;
public const int Split = 0x10;
public const int Authentication = 0x20;
public const int Shared = 0x80;
private static byte[] IntToByteArray(
int v)
{
byte[] tmp = new byte[4];
int size = 0;
for (int i = 0; i != 4; i++)
{
tmp[i] = (byte)(v >> (i * 8));
if (tmp[i] != 0)
{
size = i;
}
}
byte[] data = new byte[size + 1];
Array.Copy(tmp, 0, data, 0, data.Length);
return data;
}
public KeyFlags(
bool critical,
bool isLongLength,
byte[] data)
: base(SignatureSubpacketTag.KeyFlags, critical, isLongLength, data)
{
}
public KeyFlags(
bool critical,
int flags)
: base(SignatureSubpacketTag.KeyFlags, critical, false, IntToByteArray(flags))
{
}
/// <summary>
/// Return the flag values contained in the first 4 octets (note: at the moment
/// the standard only uses the first one).
/// </summary>
public int Flags
{
get
{
int flags = 0;
for (int i = 0; i != data.Length; i++)
{
flags |= (data[i] & 0xff) << (i * 8);
}
return flags;
}
}
}
}