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

org.bouncycastle.asn1.est.AttrOrOID Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8. Note: this package includes the NTRU encryption algorithms.

There is a newer version: 1.70
Show newest version
package org.bouncycastle.asn1.est;

import java.io.IOException;

import org.bouncycastle.asn1.ASN1Choice;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.pkcs.Attribute;

/**
 * 
 *    AttrOrOID ::= CHOICE (oid OBJECT IDENTIFIER, attribute Attribute }
 * 
*/ public class AttrOrOID extends ASN1Object implements ASN1Choice { private final ASN1ObjectIdentifier oid; private final Attribute attribute; public AttrOrOID(ASN1ObjectIdentifier oid) { this.oid = oid; attribute = null; } public AttrOrOID(Attribute attribute) { this.oid = null; this.attribute = attribute; } public static AttrOrOID getInstance( Object obj) { if (obj instanceof AttrOrOID) { return (AttrOrOID)obj; } if (obj != null) { if (obj instanceof ASN1Encodable) { ASN1Encodable asn1Prim = ((ASN1Encodable)obj).toASN1Primitive(); if (asn1Prim instanceof ASN1ObjectIdentifier) { return new AttrOrOID(ASN1ObjectIdentifier.getInstance(asn1Prim)); } if (asn1Prim instanceof ASN1Sequence) { return new AttrOrOID(Attribute.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 isOid() { return oid != null; } public ASN1ObjectIdentifier getOid() { return oid; } public Attribute getAttribute() { return attribute; } public ASN1Primitive toASN1Primitive() { if (oid != null) { return oid; } return attribute.toASN1Primitive(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy