
org.spongycastle.asn1.cmc.BodyPartReference Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle
intended for the Android platform. Android unfortunately ships with a stripped-down version of
Bouncy Castle, which prevents easy upgrades - Spongy Castle overcomes this and provides a full,
up-to-date version of the Bouncy Castle cryptographic libs.
The newest version!
package org.spongycastle.asn1.cmc;
import java.io.IOException;
import org.spongycastle.asn1.ASN1Choice;
import org.spongycastle.asn1.ASN1Encodable;
import org.spongycastle.asn1.ASN1Integer;
import org.spongycastle.asn1.ASN1Object;
import org.spongycastle.asn1.ASN1Primitive;
import org.spongycastle.asn1.ASN1Sequence;
/**
*
* BodyPartReference ::= CHOICE {
* bodyPartID BodyPartID,
* bodyPartPath BodyPartPath
* }
*
*/
public class BodyPartReference
extends ASN1Object
implements ASN1Choice
{
private final BodyPartID bodyPartID;
private final BodyPartPath bodyPartPath;
public BodyPartReference(BodyPartID bodyPartID)
{
this.bodyPartID = bodyPartID;
this.bodyPartPath = null;
}
public BodyPartReference(BodyPartPath bodyPartPath)
{
this.bodyPartID = null;
this.bodyPartPath = bodyPartPath;
}
public static BodyPartReference getInstance(
Object obj)
{
if (obj instanceof BodyPartReference)
{
return (BodyPartReference)obj;
}
if (obj != null)
{
if (obj instanceof ASN1Encodable)
{
ASN1Encodable asn1Prim = ((ASN1Encodable)obj).toASN1Primitive();
if (asn1Prim instanceof ASN1Integer)
{
return new BodyPartReference(BodyPartID.getInstance(asn1Prim));
}
if (asn1Prim instanceof ASN1Sequence)
{
return new BodyPartReference(BodyPartPath.getInstance(asn1Prim));
}
}
if (obj instanceof byte[])
{
try
{
return getInstance(ASN1Primitive.fromByteArray((byte[])obj));
}
catch (IOException e)
{
throw new IllegalArgumentException("unknown encoding in getInstance()");
}
}
throw new IllegalArgumentException("unknown object in getInstance(): " + obj.getClass().getName());
}
return null;
}
public boolean isBodyPartID()
{
return bodyPartID != null;
}
public BodyPartID getBodyPartID()
{
return bodyPartID;
}
public BodyPartPath getBodyPartPath()
{
return bodyPartPath;
}
public ASN1Primitive toASN1Primitive()
{
if (bodyPartID != null)
{
return bodyPartID.toASN1Primitive();
}
else
{
return bodyPartPath.toASN1Primitive();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy