All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.spongycastle.asn1.icao.CscaMasterList Maven / Gradle / Ivy

Go to download

Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle intended for Android. Android ships with a stripped-down version of Bouncy Castle - this causes classloader collisions if you try to add an alternative (updated/complete) Bouncy Castle jar. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5.

The newest version!
package org.spongycastle.asn1.icao;

import org.spongycastle.asn1.ASN1Encodable;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.ASN1Set;
import org.spongycastle.asn1.DERInteger;
import org.spongycastle.asn1.DERObject;
import org.spongycastle.asn1.DERSequence;
import org.spongycastle.asn1.DERSet;
import org.spongycastle.asn1.x509.X509CertificateStructure;

/**
 * The CscaMasterList object. This object can be wrapped in a
 * CMSSignedData to be published in LDAP.
 *
 * 
 * CscaMasterList ::= SEQUENCE {
 *   version                CscaMasterListVersion,
 *   certList               SET OF Certificate }
 *   
 * CscaMasterListVersion :: INTEGER {v0(0)}
 * 
*/ public class CscaMasterList extends ASN1Encodable { private DERInteger version = new DERInteger(0); private X509CertificateStructure[] certList; public static CscaMasterList getInstance( Object obj) { if (obj instanceof CscaMasterList) { return (CscaMasterList)obj; } else if (obj != null) { return new CscaMasterList(ASN1Sequence.getInstance(obj)); } return null; } private CscaMasterList( ASN1Sequence seq) { if (seq == null || seq.size() == 0) { throw new IllegalArgumentException( "null or empty sequence passed."); } if (seq.size() != 2) { throw new IllegalArgumentException( "Incorrect sequence size: " + seq.size()); } version = DERInteger.getInstance(seq.getObjectAt(0)); ASN1Set certSet = ASN1Set.getInstance(seq.getObjectAt(1)); certList = new X509CertificateStructure[certSet.size()]; for (int i = 0; i < certList.length; i++) { certList[i] = X509CertificateStructure.getInstance(certSet.getObjectAt(i)); } } public CscaMasterList( X509CertificateStructure[] certStructs) { certList = copyCertList(certStructs); } public int getVersion() { return version.getValue().intValue(); } public X509CertificateStructure[] getCertStructs() { return copyCertList(certList); } private X509CertificateStructure[] copyCertList(X509CertificateStructure[] orig) { X509CertificateStructure[] certs = new X509CertificateStructure[orig.length]; for (int i = 0; i != certs.length; i++) { certs[i] = orig[i]; } return certs; } public DERObject toASN1Object() { ASN1EncodableVector seq = new ASN1EncodableVector(); seq.add(version); ASN1EncodableVector certSet = new ASN1EncodableVector(); for (int i = 0; i < certList.length; i++) { certSet.add(certList[i]); } seq.add(new DERSet(certSet)); return new DERSequence(seq); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy