org.bouncycastle.oer.its.BasePublicEncryptionKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcutil-jdk15on Show documentation
Show all versions of bcutil-jdk15on 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 JDK 1.5 and up.
The newest version!
package org.bouncycastle.oer.its;
import org.bouncycastle.asn1.ASN1Choice;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERTaggedObject;
/**
* BasePublicEncryptionKey ::= CHOICE {
* eciesNistP256 EccP256CurvePoint,
* eciesBrainpoolP256r1 EccP256CurvePoint,
* ...
* }
*/
public class BasePublicEncryptionKey
extends ASN1Object
implements ASN1Choice
{
public static final int eciesNistP256 = 0;
public static final int eciesBrainpoolP256r1 = 1;
public static final int extension = 2;
private final int choice;
private final ASN1Encodable value;
public BasePublicEncryptionKey(int choice, ASN1Encodable value)
{
this.choice = choice;
this.value = value;
}
public static BasePublicEncryptionKey getInstance(Object objectAt)
{
if (objectAt instanceof BasePublicEncryptionKey)
{
return (BasePublicEncryptionKey)objectAt;
}
ASN1TaggedObject dto = ASN1TaggedObject.getInstance(objectAt);
ASN1Encodable value;
switch (dto.getTagNo())
{
case eciesNistP256:
case eciesBrainpoolP256r1:
value = EccP256CurvePoint.getInstance(dto.getObject());
break;
case extension:
value = DEROctetString.getInstance(dto.getObject());
break;
default:
throw new IllegalStateException("unknown choice " + dto.getTagNo());
}
return new BasePublicEncryptionKey(dto.getTagNo(), value);
}
public int getChoice()
{
return choice;
}
public ASN1Encodable getValue()
{
return value;
}
public ASN1Primitive toASN1Primitive()
{
return new DERTaggedObject(choice, value);
}
public static class Builder
{
private int choice;
private ASN1Encodable value;
public Builder setChoice(int choice)
{
this.choice = choice;
return this;
}
public Builder setValue(EccCurvePoint value)
{
this.value = value;
return this;
}
public BasePublicEncryptionKey createBasePublicEncryptionKey()
{
return new BasePublicEncryptionKey(choice, value);
}
}
}