org.spongycastle.asn1.x509.SubjectDirectoryAttributes 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.
The newest version!
package org.spongycastle.asn1.x509;
import java.util.Enumeration;
import java.util.Vector;
import org.spongycastle.asn1.ASN1Encodable;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.DERObject;
import org.spongycastle.asn1.DERSequence;
/**
* This extension may contain further X.500 attributes of the subject. See also
* RFC 3039.
*
*
* SubjectDirectoryAttributes ::= Attributes
* Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
* Attribute ::= SEQUENCE
* {
* type AttributeType
* values SET OF AttributeValue
* }
*
* AttributeType ::= OBJECT IDENTIFIER
* AttributeValue ::= ANY DEFINED BY AttributeType
*
*
* @see org.spongycastle.asn1.x509.X509Name for AttributeType ObjectIdentifiers.
*/
public class SubjectDirectoryAttributes
extends ASN1Encodable
{
private Vector attributes = new Vector();
public static SubjectDirectoryAttributes getInstance(
Object obj)
{
if (obj == null || obj instanceof SubjectDirectoryAttributes)
{
return (SubjectDirectoryAttributes)obj;
}
if (obj instanceof ASN1Sequence)
{
return new SubjectDirectoryAttributes((ASN1Sequence)obj);
}
throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
}
/**
* Constructor from ASN1Sequence.
*
* The sequence is of type SubjectDirectoryAttributes:
*
*
* SubjectDirectoryAttributes ::= Attributes
* Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
* Attribute ::= SEQUENCE
* {
* type AttributeType
* values SET OF AttributeValue
* }
*
* AttributeType ::= OBJECT IDENTIFIER
* AttributeValue ::= ANY DEFINED BY AttributeType
*
*
* @param seq
* The ASN.1 sequence.
*/
public SubjectDirectoryAttributes(ASN1Sequence seq)
{
Enumeration e = seq.getObjects();
while (e.hasMoreElements())
{
ASN1Sequence s = ASN1Sequence.getInstance(e.nextElement());
attributes.addElement(new Attribute(s));
}
}
/**
* Constructor from a vector of attributes.
*
* The vector consists of attributes of type {@link Attribute Attribute}
*
* @param attributes
* The attributes.
*
*/
public SubjectDirectoryAttributes(Vector attributes)
{
Enumeration e = attributes.elements();
while (e.hasMoreElements())
{
this.attributes.addElement(e.nextElement());
}
}
/**
* Produce an object suitable for an ASN1OutputStream.
*
* Returns:
*
*
* SubjectDirectoryAttributes ::= Attributes
* Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
* Attribute ::= SEQUENCE
* {
* type AttributeType
* values SET OF AttributeValue
* }
*
* AttributeType ::= OBJECT IDENTIFIER
* AttributeValue ::= ANY DEFINED BY AttributeType
*
*
* @return a DERObject
*/
public DERObject toASN1Object()
{
ASN1EncodableVector vec = new ASN1EncodableVector();
Enumeration e = attributes.elements();
while (e.hasMoreElements())
{
vec.add((Attribute)e.nextElement());
}
return new DERSequence(vec);
}
/**
* @return Returns the attributes.
*/
public Vector getAttributes()
{
return attributes;
}
}