01: package org.bouncycastle.bcpg.sig;
02:
03: import java.util.Date;
04:
05: import org.bouncycastle.bcpg.SignatureSubpacket;
06: import org.bouncycastle.bcpg.SignatureSubpacketTags;
07:
08: /**
09: * packet giving signature creation time.
10: */
11: public class SignatureCreationTime extends SignatureSubpacket {
12: protected static byte[] timeToBytes(Date date) {
13: byte[] data = new byte[4];
14: long t = date.getTime() / 1000;
15:
16: data[0] = (byte) (t >> 24);
17: data[1] = (byte) (t >> 16);
18: data[2] = (byte) (t >> 8);
19: data[3] = (byte) t;
20:
21: return data;
22: }
23:
24: public SignatureCreationTime(boolean critical, byte[] data) {
25: super (SignatureSubpacketTags.CREATION_TIME, critical, data);
26: }
27:
28: public SignatureCreationTime(boolean critical, Date date) {
29: super (SignatureSubpacketTags.CREATION_TIME, critical,
30: timeToBytes(date));
31: }
32:
33: public Date getTime() {
34: long time = ((long) (data[0] & 0xff) << 24)
35: | ((data[1] & 0xff) << 16) | ((data[2] & 0xff) << 8)
36: | (data[3] & 0xff);
37:
38: return new Date(time * 1000);
39: }
40: }
|