while (it.hasNext())
if (set.size() != 0)
    public static CMSSignedData replaceCertificatesAndCRLs(        CMSSignedData   signedData,        CertStore       certsAndCrls)        throws CMSException    {        //        // copy        //        CMSSignedData   cms = new CMSSignedData(signedData);                //        // replace the store        //        cms.certStore = certsAndCrls;                //        // replace the certs and crls in the SignedData object        //        ASN1EncodableVector v = new ASN1EncodableVector();                try        {            Iterator  it = certsAndCrls.getCertificates(null).iterator();            while (it.hasNext())            {                X509Certificate         c = (X509Certificate)it.next();                v.add(new X509CertificateStructure(                                        (ASN1Sequence)makeObj(c.getEncoded())));            }        }        catch (CertStoreException e)        {            throw new CMSException("error getting certs from certStore", e);        }        catch (IOException e)        {            throw new CMSException("error processing certs", e);        }        catch (CertificateEncodingException e)        {            throw new CMSException("error encoding certs", e);        }        ASN1Set             certs = null;                if (v.size() > 0)        {            certs = new DERSet(v);        }                v = new ASN1EncodableVector();                try        {            Iterator    it = certsAndCrls.getCRLs(null).iterator();            while (it.hasNext())            {                X509CRL                 c = (X509CRL)it.next();                v.add(new CertificateList(                                        (ASN1Sequence)makeObj(c.getEncoded())));            }        }        catch (CertStoreException e)        {            throw new CMSException("error getting crls from certStore", e);        }        catch (IOException e)        {            throw new CMSException("error processing crls", e);        }        catch (CRLException e)        {            throw new CMSException("error encoding crls", e);        }        ASN1Set             crls = null;                if (v.size() > 0)        {            crls = new DERSet(v);        }                //        // replace the CMS structure.        //        cms.signedData = new SignedData(signedData.signedData.getDigestAlgorithms(),                                    signedData.signedData.getEncapContentInfo(),                                   certs,                                   crls,                                   signedData.signedData.getSignerInfos());                //        // replace the contentInfo with the new one        //        cms.contentInfo = new ContentInfo(cms.contentInfo.getContentType(), cms.signedData);                return cms;    }