513 if (certificates[i] instanceof X509CertImpl)
514 implCerts[i] = (X509CertImpl) certificates[i];
515 else {
516 try {
517 byte[] encoded = certificates[i].getEncoded();
518 implCerts[i] = new X509CertImpl(encoded);
519 } catch (CertificateException ce) {
520 throw new IOException(ce);
521 }
522 }
523 }
524
525 // Add the certificate set (tagged with [0] IMPLICIT)
526 // to the signed data
527 signedData.putOrderedSetOf((byte)0xA0, implCerts);
528 }
529
530 // CRLs (optional)
531 if (crls != null && crls.length != 0) {
532 // cast to X509CRLImpl[] since X509CRLImpl implements DerEncoder
533 Set<X509CRLImpl> implCRLs = new HashSet<X509CRLImpl>(crls.length);
534 for (X509CRL crl: crls) {
535 if (crl instanceof X509CRLImpl)
536 implCRLs.add((X509CRLImpl) crl);
537 else {
538 try {
539 byte[] encoded = crl.getEncoded();
540 implCRLs.add(new X509CRLImpl(encoded));
541 } catch (CRLException ce) {
542 throw new IOException(ce);
543 }
544 }
545 }
546
547 // Add the CRL set (tagged with [1] IMPLICIT)
548 // to the signed data
549 signedData.putOrderedSetOf((byte)0xA1,
550 implCRLs.toArray(new X509CRLImpl[implCRLs.size()]));
551 }
552
553 // signerInfos
573 *
574 * @exception NoSuchAlgorithmException on unrecognized algorithms.
575 * @exception SignatureException on signature handling errors.
576 */
577 public SignerInfo verify(SignerInfo info, byte[] bytes)
578 throws NoSuchAlgorithmException, SignatureException {
579 return info.verify(this, bytes);
580 }
581
582 /**
583 * Returns all signerInfos which self-verify.
584 *
585 * @param bytes the DER encoded content information.
586 *
587 * @exception NoSuchAlgorithmException on unrecognized algorithms.
588 * @exception SignatureException on signature handling errors.
589 */
590 public SignerInfo[] verify(byte[] bytes)
591 throws NoSuchAlgorithmException, SignatureException {
592
593 Vector<SignerInfo> intResult = new Vector<SignerInfo>();
594 for (int i = 0; i < signerInfos.length; i++) {
595
596 SignerInfo signerInfo = verify(signerInfos[i], bytes);
597 if (signerInfo != null) {
598 intResult.addElement(signerInfo);
599 }
600 }
601 if (!intResult.isEmpty()) {
602
603 SignerInfo[] result = new SignerInfo[intResult.size()];
604 intResult.copyInto(result);
605 return result;
606 }
607 return null;
608 }
609
610 /**
611 * Returns all signerInfos which self-verify.
612 *
613 * @exception NoSuchAlgorithmException on unrecognized algorithms.
|
513 if (certificates[i] instanceof X509CertImpl)
514 implCerts[i] = (X509CertImpl) certificates[i];
515 else {
516 try {
517 byte[] encoded = certificates[i].getEncoded();
518 implCerts[i] = new X509CertImpl(encoded);
519 } catch (CertificateException ce) {
520 throw new IOException(ce);
521 }
522 }
523 }
524
525 // Add the certificate set (tagged with [0] IMPLICIT)
526 // to the signed data
527 signedData.putOrderedSetOf((byte)0xA0, implCerts);
528 }
529
530 // CRLs (optional)
531 if (crls != null && crls.length != 0) {
532 // cast to X509CRLImpl[] since X509CRLImpl implements DerEncoder
533 Set<X509CRLImpl> implCRLs = new HashSet<>(crls.length);
534 for (X509CRL crl: crls) {
535 if (crl instanceof X509CRLImpl)
536 implCRLs.add((X509CRLImpl) crl);
537 else {
538 try {
539 byte[] encoded = crl.getEncoded();
540 implCRLs.add(new X509CRLImpl(encoded));
541 } catch (CRLException ce) {
542 throw new IOException(ce);
543 }
544 }
545 }
546
547 // Add the CRL set (tagged with [1] IMPLICIT)
548 // to the signed data
549 signedData.putOrderedSetOf((byte)0xA1,
550 implCRLs.toArray(new X509CRLImpl[implCRLs.size()]));
551 }
552
553 // signerInfos
573 *
574 * @exception NoSuchAlgorithmException on unrecognized algorithms.
575 * @exception SignatureException on signature handling errors.
576 */
577 public SignerInfo verify(SignerInfo info, byte[] bytes)
578 throws NoSuchAlgorithmException, SignatureException {
579 return info.verify(this, bytes);
580 }
581
582 /**
583 * Returns all signerInfos which self-verify.
584 *
585 * @param bytes the DER encoded content information.
586 *
587 * @exception NoSuchAlgorithmException on unrecognized algorithms.
588 * @exception SignatureException on signature handling errors.
589 */
590 public SignerInfo[] verify(byte[] bytes)
591 throws NoSuchAlgorithmException, SignatureException {
592
593 Vector<SignerInfo> intResult = new Vector<>();
594 for (int i = 0; i < signerInfos.length; i++) {
595
596 SignerInfo signerInfo = verify(signerInfos[i], bytes);
597 if (signerInfo != null) {
598 intResult.addElement(signerInfo);
599 }
600 }
601 if (!intResult.isEmpty()) {
602
603 SignerInfo[] result = new SignerInfo[intResult.size()];
604 intResult.copyInto(result);
605 return result;
606 }
607 return null;
608 }
609
610 /**
611 * Returns all signerInfos which self-verify.
612 *
613 * @exception NoSuchAlgorithmException on unrecognized algorithms.
|