001: package org.bouncycastle.openpgp;
002:
003: import org.bouncycastle.bcpg.SignatureSubpacket;
004: import org.bouncycastle.bcpg.SignatureSubpacketTags;
005: import org.bouncycastle.bcpg.sig.Exportable;
006: import org.bouncycastle.bcpg.sig.KeyExpirationTime;
007: import org.bouncycastle.bcpg.sig.KeyFlags;
008: import org.bouncycastle.bcpg.sig.NotationData;
009: import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
010: import org.bouncycastle.bcpg.sig.PrimaryUserID;
011: import org.bouncycastle.bcpg.sig.Revocable;
012: import org.bouncycastle.bcpg.sig.SignatureCreationTime;
013: import org.bouncycastle.bcpg.sig.SignatureExpirationTime;
014: import org.bouncycastle.bcpg.sig.SignerUserID;
015: import org.bouncycastle.bcpg.sig.TrustSignature;
016:
017: import java.util.ArrayList;
018: import java.util.Date;
019: import java.util.List;
020:
021: /**
022: * Generator for signature subpackets.
023: */
024: public class PGPSignatureSubpacketGenerator {
025: List list = new ArrayList();
026:
027: public PGPSignatureSubpacketGenerator() {
028: }
029:
030: public void setRevocable(boolean isCritical, boolean isRevocable) {
031: list.add(new Revocable(isCritical, isRevocable));
032: }
033:
034: public void setExportable(boolean isCritical, boolean isExportable) {
035: list.add(new Exportable(isCritical, isExportable));
036: }
037:
038: public void setTrust(boolean isCritical, int depth, int trustAmount) {
039: list.add(new TrustSignature(isCritical, depth, trustAmount));
040: }
041:
042: /**
043: * Set the number of seconds a key is valid for after the time of its creation.
044: * A value of zero means the key never expires.
045: *
046: * @param isCritical true if should be treated as critical, false otherwise.
047: * @param seconds
048: */
049: public void setKeyExpirationTime(boolean isCritical, long seconds) {
050: list.add(new KeyExpirationTime(isCritical, seconds));
051: }
052:
053: /**
054: * Set the number of seconds a signature is valid for after the time of its creation.
055: * A value of zero means the signature never expires.
056: *
057: * @param isCritical true if should be treated as critical, false otherwise.
058: * @param seconds
059: */
060: public void setSignatureExpirationTime(boolean isCritical,
061: long seconds) {
062: list.add(new SignatureExpirationTime(isCritical, seconds));
063: }
064:
065: /**
066: * Set the creation time for the signature.
067: * <p>
068: * Note: this overrides the generation of a creation time when the signature
069: * is generated.
070: */
071: public void setSignatureCreationTime(boolean isCritical, Date date) {
072: list.add(new SignatureCreationTime(isCritical, date));
073: }
074:
075: public void setPreferredHashAlgorithms(boolean isCritical,
076: int[] algorithms) {
077: list.add(new PreferredAlgorithms(
078: SignatureSubpacketTags.PREFERRED_HASH_ALGS, isCritical,
079: algorithms));
080: }
081:
082: public void setPreferredSymmetricAlgorithms(boolean isCritical,
083: int[] algorithms) {
084: list.add(new PreferredAlgorithms(
085: SignatureSubpacketTags.PREFERRED_SYM_ALGS, isCritical,
086: algorithms));
087: }
088:
089: public void setPreferredCompressionAlgorithms(boolean isCritical,
090: int[] algorithms) {
091: list.add(new PreferredAlgorithms(
092: SignatureSubpacketTags.PREFERRED_COMP_ALGS, isCritical,
093: algorithms));
094: }
095:
096: public void setKeyFlags(boolean isCritical, int flags) {
097: list.add(new KeyFlags(isCritical, flags));
098: }
099:
100: public void setSignerUserID(boolean isCritical, String userID) {
101: if (userID == null) {
102: throw new IllegalArgumentException(
103: "attempt to set null SignerUserID");
104: }
105:
106: list.add(new SignerUserID(isCritical, userID));
107: }
108:
109: public void setPrimaryUserID(boolean isCritical,
110: boolean isPrimaryUserID) {
111: list.add(new PrimaryUserID(isCritical, isPrimaryUserID));
112: }
113:
114: public void setNotationData(boolean isCritical,
115: boolean isHumanReadable, String notationName,
116: String notationValue) {
117: list.add(new NotationData(isCritical, isHumanReadable,
118: notationName, notationValue));
119: }
120:
121: public PGPSignatureSubpacketVector generate() {
122: return new PGPSignatureSubpacketVector(
123: (SignatureSubpacket[]) list
124: .toArray(new SignatureSubpacket[list.size()]));
125: }
126: }
|