*/
public PKCS7SignedData(BERReader ber)
throws CRLException, CertificateException, IOException
{
CertificateFactory x509 = CertificateFactory.getInstance("X509");
DERValue val = ber.read();
if (!val.isConstructed())
throw new BEREncodingException("malformed ContentInfo");
val = ber.read();
if (val.getTag() != BER.OBJECT_IDENTIFIER)
throw new BEREncodingException("malformed ContentType");
if (!PKCS7_SIGNED_DATA.equals(val.getValue()))
throw new BEREncodingException("content is not SignedData");
val = ber.read();
if (val.getTag() != 0)
throw new BEREncodingException("malformed Content");
val = ber.read();
if (!val.isConstructed())
throw new BEREncodingException("malformed SignedData");
if (Configuration.DEBUG)
log.fine("SignedData: " + val);
val = ber.read();
if (val.getTag() != BER.INTEGER)
throw new BEREncodingException("expecting Version");
version = (BigInteger) val.getValue();
if (Configuration.DEBUG)
log.fine(" Version: " + version);
digestAlgorithms = new HashSet();
val = ber.read();
if (!val.isConstructed())
throw new BEREncodingException("malformed DigestAlgorithmIdentifiers");
if (Configuration.DEBUG)
log.fine(" DigestAlgorithmIdentifiers: " + val);
int count = 0;
DERValue val2 = ber.read();
while (val2 != BER.END_OF_SEQUENCE &&
(val.getLength() > 0 && val.getLength() > count))
{
if (!val2.isConstructed())
throw new BEREncodingException("malformed AlgorithmIdentifier");
if (Configuration.DEBUG)
log.fine(" AlgorithmIdentifier: " + val2);
count += val2.getEncodedLength();
val2 = ber.read();
if (val2.getTag() != BER.OBJECT_IDENTIFIER)
throw new BEREncodingException("malformed AlgorithmIdentifier");
if (Configuration.DEBUG)
log.fine(" digestAlgorithmIdentifiers OID: " + val2.getValue());
List algId = new ArrayList(2);
algId.add(val2.getValue());
val2 = ber.read();
if (val2 != BER.END_OF_SEQUENCE)
{
count += val2.getEncodedLength();
if (val2.getTag() == BER.NULL)
algId.add(null);
else
algId.add(val2.getEncoded());
if (val2.isConstructed())
ber.skip(val2.getLength());
if (BERValue.isIndefinite(val))
val2 = ber.read();
}
else
algId.add(null);
if (Configuration.DEBUG)
{
log.fine(" digestAlgorithmIdentifiers params: ");
log.fine(Util.dumpString((byte[]) algId.get(1),
" digestAlgorithmIdentifiers params: "));
}
digestAlgorithms.add(algId);
}
val = ber.read();
if (!val.isConstructed())
throw new BEREncodingException("malformed ContentInfo");
if (Configuration.DEBUG)
log.fine(" ContentInfo: " + val);
val2 = ber.read();
if (val2.getTag() != BER.OBJECT_IDENTIFIER)
throw new BEREncodingException("malformed ContentType");
contentType = (OID) val2.getValue();
if (Configuration.DEBUG)
log.fine(" ContentType OID: " + contentType);
if (BERValue.isIndefinite(val)
|| (val.getLength() > 0 && val.getLength() > val2.getEncodedLength()))
{
val2 = ber.read();
if (val2 != BER.END_OF_SEQUENCE)
{
content = val2.getEncoded();
if (BERValue.isIndefinite(val))
val2 = ber.read();
}
}
if (Configuration.DEBUG)
{
log.fine(" Content: ");
log.fine(Util.dumpString(content, " Content: "));
}
val = ber.read();
if (val.getTag() == 0)
{
if (!val.isConstructed())
throw new BEREncodingException("malformed ExtendedCertificatesAndCertificates");
if (Configuration.DEBUG)
log.fine(" ExtendedCertificatesAndCertificates: " + val);
count = 0;
val2 = ber.read();
List certs = new LinkedList();
while (val2 != BER.END_OF_SEQUENCE &&
(val.getLength() > 0 && val.getLength() > count))
{
Certificate cert =
x509.generateCertificate(new ByteArrayInputStream(val2.getEncoded()));
if (Configuration.DEBUG)
log.fine(" Certificate: " + cert);
certs.add(cert);
count += val2.getEncodedLength();
ber.skip(val2.getLength());
if (BERValue.isIndefinite(val) || val.getLength() > count)
val2 = ber.read();
}
certificates = (Certificate[]) certs.toArray(new Certificate[certs.size()]);
val = ber.read();
}
if (val.getTag() == 1)
{
if (!val.isConstructed())
throw new BEREncodingException("malformed CertificateRevocationLists");
if (Configuration.DEBUG)
log.fine(" CertificateRevocationLists: " + val);
count = 0;
val2 = ber.read();
List crls = new LinkedList();
while (val2 != BER.END_OF_SEQUENCE &&
(val.getLength() > 0 && val.getLength() > count))
{
CRL crl = x509.generateCRL(new ByteArrayInputStream(val2.getEncoded()));
if (Configuration.DEBUG)
log.fine(" CRL: " + crl);
crls.add(crl);
count += val2.getEncodedLength();
ber.skip(val2.getLength());
if (BERValue.isIndefinite(val) || val.getLength() > count)
val2 = ber.read();
}
this.crls = (CRL[]) crls.toArray(new CRL[crls.size()]);
val = ber.read();