org.bouncycastle.asn1.ess.ESSCertID Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcutil-lts8on Show documentation
Show all versions of bcutil-lts8on Show documentation
The Bouncy Castle Java APIs for ASN.1 extension and utility APIs used to support bcpkix and bctls. This jar contains APIs for Java 8 and later.
The newest version!
package org.bouncycastle.asn1.ess;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.x509.IssuerSerial;
import org.bouncycastle.util.Arrays;
public class ESSCertID
extends ASN1Object
{
private ASN1OctetString certHash;
private IssuerSerial issuerSerial;
public static ESSCertID getInstance(Object o)
{
if (o instanceof ESSCertID)
{
return (ESSCertID)o;
}
else if (o != null)
{
return new ESSCertID(ASN1Sequence.getInstance(o));
}
return null;
}
/**
* constructor
*/
private ESSCertID(ASN1Sequence seq)
{
if (seq.size() < 1 || seq.size() > 2)
{
throw new IllegalArgumentException("Bad sequence size: " + seq.size());
}
certHash = ASN1OctetString.getInstance(seq.getObjectAt(0));
if (seq.size() > 1)
{
issuerSerial = IssuerSerial.getInstance(seq.getObjectAt(1));
}
}
public ESSCertID(
byte[] hash)
{
certHash = new DEROctetString(Arrays.clone(hash));
}
public ESSCertID(
byte[] hash,
IssuerSerial issuerSerial)
{
this.certHash = new DEROctetString(Arrays.clone(hash));
this.issuerSerial = issuerSerial;
}
public byte[] getCertHash()
{
return certHash.getOctets();
}
public IssuerSerial getIssuerSerial()
{
return issuerSerial;
}
/**
*
* ESSCertID ::= SEQUENCE {
* certHash Hash,
* issuerSerial IssuerSerial OPTIONAL }
*
*/
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector(2);
v.add(certHash);
if (issuerSerial != null)
{
v.add(issuerSerial);
}
return new DERSequence(v);
}
}