01: package org.bouncycastle.bcpg;
02:
03: import java.io.*;
04:
05: /**
06: * generic signature object
07: */
08: public class OnePassSignaturePacket extends ContainedPacket {
09: private int version;
10: private int sigType;
11: private int hashAlgorithm;
12: private int keyAlgorithm;
13: private long keyID;
14: private int nested;
15:
16: OnePassSignaturePacket(BCPGInputStream in) throws IOException {
17: version = in.read();
18: sigType = in.read();
19: hashAlgorithm = in.read();
20: keyAlgorithm = in.read();
21:
22: keyID |= (long) in.read() << 56;
23: keyID |= (long) in.read() << 48;
24: keyID |= (long) in.read() << 40;
25: keyID |= (long) in.read() << 32;
26: keyID |= (long) in.read() << 24;
27: keyID |= (long) in.read() << 16;
28: keyID |= (long) in.read() << 8;
29: keyID |= in.read();
30:
31: nested = in.read();
32: }
33:
34: public OnePassSignaturePacket(int sigType, int hashAlgorithm,
35: int keyAlgorithm, long keyID, boolean isNested) {
36: this .version = 3;
37: this .sigType = sigType;
38: this .hashAlgorithm = hashAlgorithm;
39: this .keyAlgorithm = keyAlgorithm;
40: this .keyID = keyID;
41: this .nested = (isNested) ? 0 : 1;
42: }
43:
44: /**
45: * Return the signature type.
46: * @return the signature type
47: */
48: public int getSignatureType() {
49: return sigType;
50: }
51:
52: /**
53: * return the encryption algorithm tag
54: */
55: public int getKeyAlgorithm() {
56: return keyAlgorithm;
57: }
58:
59: /**
60: * return the hashAlgorithm tag
61: */
62: public int getHashAlgorithm() {
63: return hashAlgorithm;
64: }
65:
66: /**
67: * @return long
68: */
69: public long getKeyID() {
70: return keyID;
71: }
72:
73: /**
74: *
75: */
76: public void encode(BCPGOutputStream out) throws IOException {
77: ByteArrayOutputStream bOut = new ByteArrayOutputStream();
78: BCPGOutputStream pOut = new BCPGOutputStream(bOut);
79:
80: pOut.write(version);
81: pOut.write(sigType);
82: pOut.write(hashAlgorithm);
83: pOut.write(keyAlgorithm);
84:
85: pOut.write((byte) (keyID >> 56));
86: pOut.write((byte) (keyID >> 48));
87: pOut.write((byte) (keyID >> 40));
88: pOut.write((byte) (keyID >> 32));
89: pOut.write((byte) (keyID >> 24));
90: pOut.write((byte) (keyID >> 16));
91: pOut.write((byte) (keyID >> 8));
92: pOut.write((byte) (keyID));
93:
94: pOut.write(nested);
95:
96: out.writePacket(ONE_PASS_SIGNATURE, bOut.toByteArray(), true);
97: }
98: }
|