001: package org.bouncycastle.asn1.cms;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.ASN1Sequence;
006: import org.bouncycastle.asn1.ASN1Set;
007: import org.bouncycastle.asn1.ASN1TaggedObject;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERSequence;
010: import org.bouncycastle.asn1.DERTaggedObject;
011:
012: public class OriginatorInfo extends ASN1Encodable {
013: private ASN1Set certs;
014: private ASN1Set crls;
015:
016: public OriginatorInfo(ASN1Set certs, ASN1Set crls) {
017: this .certs = certs;
018: this .crls = crls;
019: }
020:
021: public OriginatorInfo(ASN1Sequence seq) {
022: switch (seq.size()) {
023: case 0: // empty
024: break;
025: case 1:
026: ASN1TaggedObject o = (ASN1TaggedObject) seq.getObjectAt(0);
027: switch (o.getTagNo()) {
028: case 0:
029: certs = ASN1Set.getInstance(o, false);
030: break;
031: case 1:
032: crls = ASN1Set.getInstance(o, false);
033: break;
034: default:
035: throw new IllegalArgumentException(
036: "Bad tag in OriginatorInfo: " + o.getTagNo());
037: }
038: break;
039: case 2:
040: certs = ASN1Set.getInstance((ASN1TaggedObject) seq
041: .getObjectAt(0), false);
042: crls = ASN1Set.getInstance((ASN1TaggedObject) seq
043: .getObjectAt(1), false);
044: break;
045: default:
046: throw new IllegalArgumentException("OriginatorInfo too big");
047: }
048: }
049:
050: /**
051: * return an OriginatorInfo object from a tagged object.
052: *
053: * @param obj the tagged object holding the object we want.
054: * @param explicit true if the object is meant to be explicitly
055: * tagged false otherwise.
056: * @exception IllegalArgumentException if the object held by the
057: * tagged object cannot be converted.
058: */
059: public static OriginatorInfo getInstance(ASN1TaggedObject obj,
060: boolean explicit) {
061: return getInstance(ASN1Sequence.getInstance(obj, explicit));
062: }
063:
064: /**
065: * return an OriginatorInfo object from the given object.
066: *
067: * @param obj the object we want converted.
068: * @exception IllegalArgumentException if the object cannot be converted.
069: */
070: public static OriginatorInfo getInstance(Object obj) {
071: if (obj == null || obj instanceof OriginatorInfo) {
072: return (OriginatorInfo) obj;
073: }
074:
075: if (obj instanceof ASN1Sequence) {
076: return new OriginatorInfo((ASN1Sequence) obj);
077: }
078:
079: throw new IllegalArgumentException("Invalid OriginatorInfo: "
080: + obj.getClass().getName());
081: }
082:
083: public ASN1Set getCertificates() {
084: return certs;
085: }
086:
087: public ASN1Set getCRLs() {
088: return crls;
089: }
090:
091: /**
092: * Produce an object suitable for an ASN1OutputStream.
093: * <pre>
094: * OriginatorInfo ::= SEQUENCE {
095: * certs [0] IMPLICIT CertificateSet OPTIONAL,
096: * crls [1] IMPLICIT CertificateRevocationLists OPTIONAL
097: * }
098: * </pre>
099: */
100: public DERObject toASN1Object() {
101: ASN1EncodableVector v = new ASN1EncodableVector();
102:
103: if (certs != null) {
104: v.add(new DERTaggedObject(false, 0, certs));
105: }
106:
107: if (crls != null) {
108: v.add(new DERTaggedObject(false, 1, crls));
109: }
110:
111: return new DERSequence(v);
112: }
113: }
|