certs.add(new DERTaggedObject(false, 2, new ASN1InputStream(AttrCertTest.attrCert).readObject()));
ASN1EncodableVector crls = new ASN1EncodableVector();
crls.add(new ASN1InputStream(CertPathTest.rootCrlBin).readObject());
SignedData sigData = new SignedData(new DERSet(), new ContentInfo(CMSObjectIdentifiers.data, null), new DERSet(certs), new DERSet(crls), new DERSet());
ContentInfo info = new ContentInfo(CMSObjectIdentifiers.signedData, sigData);
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
X509Certificate cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(info.getEncoded()));
if (cert == null || !areEqual(cert.getEncoded(), certs.get(0).getDERObject().getEncoded()))
{
fail("PKCS7 cert not read");
}
X509CRL crl = (X509CRL)cf.generateCRL(new ByteArrayInputStream(info.getEncoded()));
if (crl == null || !areEqual(crl.getEncoded(), crls.get(0).getDERObject().getEncoded()))
{
fail("PKCS7 crl not read");
}
Collection col = cf.generateCertificates(new ByteArrayInputStream(info.getEncoded()));
if (col.size() != 1 || !col.contains(cert))
{
fail("PKCS7 cert collection not right");
}
col = cf.generateCRLs(new ByteArrayInputStream(info.getEncoded()));
if (col.size() != 1 || !col.contains(crl))
{
fail("PKCS7 crl collection not right");
}
// data with no certificates or CRLs
sigData = new SignedData(new DERSet(), new ContentInfo(CMSObjectIdentifiers.data, null), new DERSet(), new DERSet(), new DERSet());
info = new ContentInfo(CMSObjectIdentifiers.signedData, sigData);
cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(info.getEncoded()));
if (cert != null)
{
fail("PKCS7 cert present");
}
crl = (X509CRL)cf.generateCRL(new ByteArrayInputStream(info.getEncoded()));
if (crl != null)
{
fail("PKCS7 crl present");
}
// data with absent certificates and CRLS
sigData = new SignedData(new DERSet(), new ContentInfo(CMSObjectIdentifiers.data, null), null, null, new DERSet());
info = new ContentInfo(CMSObjectIdentifiers.signedData, sigData);
cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(info.getEncoded()));
if (cert != null)
{
fail("PKCS7 cert present");
}
crl = (X509CRL)cf.generateCRL(new ByteArrayInputStream(info.getEncoded()));
if (crl != null)
{
fail("PKCS7 crl present");
}