01: package org.bouncycastle.bcpg.sig;
02:
03: import org.bouncycastle.bcpg.SignatureSubpacket;
04: import org.bouncycastle.bcpg.SignatureSubpacketTags;
05:
06: /**
07: * packet giving time after creation at which the key expires.
08: */
09: public class KeyExpirationTime extends SignatureSubpacket {
10: protected static byte[] timeToBytes(long t) {
11: byte[] data = new byte[4];
12:
13: data[0] = (byte) (t >> 24);
14: data[1] = (byte) (t >> 16);
15: data[2] = (byte) (t >> 8);
16: data[3] = (byte) t;
17:
18: return data;
19: }
20:
21: public KeyExpirationTime(boolean critical, byte[] data) {
22: super (SignatureSubpacketTags.KEY_EXPIRE_TIME, critical, data);
23: }
24:
25: public KeyExpirationTime(boolean critical, long seconds) {
26: super (SignatureSubpacketTags.KEY_EXPIRE_TIME, critical,
27: timeToBytes(seconds));
28: }
29:
30: /**
31: * Return the number of seconds after creation time a key is valid for.
32: *
33: * @return second count for key validity.
34: */
35: public long getTime() {
36: long time = ((long) (data[0] & 0xff) << 24)
37: | ((data[1] & 0xff) << 16) | ((data[2] & 0xff) << 8)
38: | (data[3] & 0xff);
39:
40: return time;
41: }
42: }
|