OnePassSignaturePacket.cs
2.09 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.IO;
namespace Org.BouncyCastle.Bcpg
{
/// <remarks>Generic signature object</remarks>
public class OnePassSignaturePacket
: ContainedPacket
{
private int version;
private int sigType;
private HashAlgorithmTag hashAlgorithm;
private PublicKeyAlgorithmTag keyAlgorithm;
private long keyId;
private int nested;
internal OnePassSignaturePacket(
BcpgInputStream bcpgIn)
{
version = bcpgIn.ReadByte();
sigType = bcpgIn.ReadByte();
hashAlgorithm = (HashAlgorithmTag) bcpgIn.ReadByte();
keyAlgorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
keyId |= (long)bcpgIn.ReadByte() << 56;
keyId |= (long)bcpgIn.ReadByte() << 48;
keyId |= (long)bcpgIn.ReadByte() << 40;
keyId |= (long)bcpgIn.ReadByte() << 32;
keyId |= (long)bcpgIn.ReadByte() << 24;
keyId |= (long)bcpgIn.ReadByte() << 16;
keyId |= (long)bcpgIn.ReadByte() << 8;
keyId |= (uint)bcpgIn.ReadByte();
nested = bcpgIn.ReadByte();
}
public OnePassSignaturePacket(
int sigType,
HashAlgorithmTag hashAlgorithm,
PublicKeyAlgorithmTag keyAlgorithm,
long keyId,
bool isNested)
{
this.version = 3;
this.sigType = sigType;
this.hashAlgorithm = hashAlgorithm;
this.keyAlgorithm = keyAlgorithm;
this.keyId = keyId;
this.nested = (isNested) ? 0 : 1;
}
public int SignatureType
{
get { return sigType; }
}
/// <summary>The encryption algorithm tag.</summary>
public PublicKeyAlgorithmTag KeyAlgorithm
{
get { return keyAlgorithm; }
}
/// <summary>The hash algorithm tag.</summary>
public HashAlgorithmTag HashAlgorithm
{
get { return hashAlgorithm; }
}
public long KeyId
{
get { return keyId; }
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
MemoryStream bOut = new MemoryStream();
BcpgOutputStream pOut = new BcpgOutputStream(bOut);
pOut.Write(
(byte) version,
(byte) sigType,
(byte) hashAlgorithm,
(byte) keyAlgorithm);
pOut.WriteLong(keyId);
pOut.WriteByte((byte) nested);
bcpgOut.WritePacket(PacketTag.OnePassSignature, bOut.ToArray(), true);
}
}
}