01: package org.bouncycastle.bcpg;
02:
03: import java.io.*;
04:
05: /**
06: * Basic type for a PGP Signature sub-packet.
07: */
08: public class SignatureSubpacket {
09: int type;
10: boolean critical;
11:
12: protected byte[] data;
13:
14: protected SignatureSubpacket(int type, boolean critical, byte[] data) {
15: this .type = type;
16: this .critical = critical;
17: this .data = data;
18: }
19:
20: public int getType() {
21: return type;
22: }
23:
24: public boolean isCritical() {
25: return critical;
26: }
27:
28: /**
29: * return the generic data making up the packet.
30: */
31: public byte[] getData() {
32: return data;
33: }
34:
35: public void encode(OutputStream out) throws IOException {
36: int bodyLen = data.length + 1;
37:
38: if (bodyLen < 192) {
39: out.write((byte) bodyLen);
40: } else if (bodyLen <= 8383) {
41: bodyLen -= 192;
42:
43: out.write((byte) (((bodyLen >> 8) & 0xff) + 192));
44: out.write((byte) bodyLen);
45: } else {
46: out.write(0xff);
47: out.write((byte) (bodyLen >> 24));
48: out.write((byte) (bodyLen >> 16));
49: out.write((byte) (bodyLen >> 8));
50: out.write((byte) bodyLen);
51: }
52:
53: if (critical) {
54: out.write(0x80 | type);
55: } else {
56: out.write(type);
57: }
58:
59: out.write(data);
60: }
61: }
|