001: package org.bouncycastle.sasn1.cms;
002:
003: import org.bouncycastle.sasn1.Asn1Integer;
004: import org.bouncycastle.sasn1.Asn1Object;
005: import org.bouncycastle.sasn1.Asn1Sequence;
006: import org.bouncycastle.sasn1.Asn1Set;
007: import org.bouncycastle.sasn1.Asn1TaggedObject;
008: import org.bouncycastle.sasn1.BerTag;
009:
010: import java.io.IOException;
011:
012: /**
013: * <pre>
014: * SignedData ::= SEQUENCE {
015: * version CMSVersion,
016: * digestAlgorithms DigestAlgorithmIdentifiers,
017: * encapContentInfo EncapsulatedContentInfo,
018: * certificates [0] IMPLICIT CertificateSet OPTIONAL,
019: * crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,
020: * signerInfos SignerInfos
021: * }
022: * </pre>
023: * @deprecated use corresponding class in org.bouncycastle.asn1.cms
024: */
025: public class SignedDataParser {
026: private Asn1Sequence _seq;
027: private Asn1Integer _version;
028: private Asn1Object _nextObject;
029: private boolean _certsCalled;
030: private boolean _crlsCalled;
031:
032: public SignedDataParser(Asn1Sequence seq) throws IOException {
033: this ._seq = seq;
034: this ._version = (Asn1Integer) seq.readObject();
035: }
036:
037: public Asn1Integer getVersion() {
038: return _version;
039: }
040:
041: public Asn1Set getDigestAlgorithms() throws IOException {
042: return (Asn1Set) _seq.readObject();
043: }
044:
045: public ContentInfoParser getEncapContentInfo() throws IOException {
046: return new ContentInfoParser((Asn1Sequence) _seq.readObject());
047: }
048:
049: public Asn1Set getCertificates() throws IOException {
050: _certsCalled = true;
051: _nextObject = _seq.readObject();
052:
053: if (_nextObject instanceof Asn1TaggedObject
054: && ((Asn1TaggedObject) _nextObject).getTagNumber() == 0) {
055: Asn1Set certs = (Asn1Set) ((Asn1TaggedObject) _nextObject)
056: .getObject(BerTag.SET, false);
057: _nextObject = null;
058:
059: return certs;
060: }
061:
062: return null;
063: }
064:
065: public Asn1Set getCrls() throws IOException {
066: if (!_certsCalled) {
067: throw new IOException("getCerts() has not been called.");
068: }
069:
070: _crlsCalled = true;
071:
072: if (_nextObject == null) {
073: _nextObject = _seq.readObject();
074: }
075:
076: if (_nextObject instanceof Asn1TaggedObject
077: && ((Asn1TaggedObject) _nextObject).getTagNumber() == 1) {
078: Asn1Set crls = (Asn1Set) ((Asn1TaggedObject) _nextObject)
079: .getObject(BerTag.SET, false);
080: _nextObject = null;
081:
082: return crls;
083: }
084:
085: return null;
086: }
087:
088: public Asn1Set getSignerInfos() throws IOException {
089: if (!_certsCalled || !_crlsCalled) {
090: throw new IOException(
091: "getCerts() and/or getCrls() has not been called.");
092: }
093:
094: if (_nextObject == null) {
095: _nextObject = _seq.readObject();
096: }
097:
098: return (Asn1Set) _nextObject;
099: }
100: }
|