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

org.bouncycastle.asn1.cmc.BodyPartReference Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for ASN.1 extension and utility APIs used to support bcpkix and bctls with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.

There is a newer version: 2.0.3
Show newest version
package org.bouncycastle.asn1.cmc;

import java.io.IOException;

import org.bouncycastle.asn1.ASN1Choice;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.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 - 2024 Weber Informatics LLC | Privacy Policy