org.spongycastle.asn1.x509.AttributeCertificate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scprov-jdk15 Show documentation
Show all versions of scprov-jdk15 Show documentation
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.
package org.spongycastle.asn1.x509;
import org.spongycastle.asn1.ASN1Encodable;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.DERBitString;
import org.spongycastle.asn1.DERObject;
import org.spongycastle.asn1.DERSequence;
public class AttributeCertificate
extends ASN1Encodable
{
AttributeCertificateInfo acinfo;
AlgorithmIdentifier signatureAlgorithm;
DERBitString signatureValue;
/**
* @param obj
* @return an AttributeCertificate object
*/
public static AttributeCertificate getInstance(Object obj)
{
if (obj instanceof AttributeCertificate)
{
return (AttributeCertificate)obj;
}
else if (obj != null)
{
return new AttributeCertificate(ASN1Sequence.getInstance(obj));
}
return null;
}
public AttributeCertificate(
AttributeCertificateInfo acinfo,
AlgorithmIdentifier signatureAlgorithm,
DERBitString signatureValue)
{
this.acinfo = acinfo;
this.signatureAlgorithm = signatureAlgorithm;
this.signatureValue = signatureValue;
}
public AttributeCertificate(
ASN1Sequence seq)
{
if (seq.size() != 3)
{
throw new IllegalArgumentException("Bad sequence size: "
+ seq.size());
}
this.acinfo = AttributeCertificateInfo.getInstance(seq.getObjectAt(0));
this.signatureAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
this.signatureValue = DERBitString.getInstance(seq.getObjectAt(2));
}
public AttributeCertificateInfo getAcinfo()
{
return acinfo;
}
public AlgorithmIdentifier getSignatureAlgorithm()
{
return signatureAlgorithm;
}
public DERBitString getSignatureValue()
{
return signatureValue;
}
/**
* Produce an object suitable for an ASN1OutputStream.
*
* AttributeCertificate ::= SEQUENCE {
* acinfo AttributeCertificateInfo,
* signatureAlgorithm AlgorithmIdentifier,
* signatureValue BIT STRING
* }
*
*/
public DERObject toASN1Object()
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(acinfo);
v.add(signatureAlgorithm);
v.add(signatureValue);
return new DERSequence(v);
}
}