com.fitbur.bouncycastle.asn1.esf.SignerAttribute Maven / Gradle / Ivy
package com.fitbur.bouncycastle.asn1.esf;
import java.util.Enumeration;
import com.fitbur.bouncycastle.asn1.ASN1EncodableVector;
import com.fitbur.bouncycastle.asn1.ASN1Object;
import com.fitbur.bouncycastle.asn1.ASN1Primitive;
import com.fitbur.bouncycastle.asn1.ASN1Sequence;
import com.fitbur.bouncycastle.asn1.ASN1TaggedObject;
import com.fitbur.bouncycastle.asn1.DERSequence;
import com.fitbur.bouncycastle.asn1.DERTaggedObject;
import com.fitbur.bouncycastle.asn1.x509.Attribute;
import com.fitbur.bouncycastle.asn1.x509.AttributeCertificate;
public class SignerAttribute
extends ASN1Object
{
private Object[] values;
public static SignerAttribute getInstance(
Object o)
{
if (o instanceof SignerAttribute)
{
return (SignerAttribute) o;
}
else if (o != null)
{
return new SignerAttribute(ASN1Sequence.getInstance(o));
}
return null;
}
private SignerAttribute(
ASN1Sequence seq)
{
int index = 0;
values = new Object[seq.size()];
for (Enumeration e = seq.getObjects(); e.hasMoreElements();)
{
ASN1TaggedObject taggedObject = ASN1TaggedObject.getInstance(e.nextElement());
if (taggedObject.getTagNo() == 0)
{
ASN1Sequence attrs = ASN1Sequence.getInstance(taggedObject, true);
Attribute[] attributes = new Attribute[attrs.size()];
for (int i = 0; i != attributes.length; i++)
{
attributes[i] = Attribute.getInstance(attrs.getObjectAt(i));
}
values[index] = attributes;
}
else if (taggedObject.getTagNo() == 1)
{
values[index] = AttributeCertificate.getInstance(ASN1Sequence.getInstance(taggedObject, true));
}
else
{
throw new IllegalArgumentException("illegal tag: " + taggedObject.getTagNo());
}
index++;
}
}
public SignerAttribute(
Attribute[] claimedAttributes)
{
this.values = new Object[1];
this.values[0] = claimedAttributes;
}
public SignerAttribute(
AttributeCertificate certifiedAttributes)
{
this.values = new Object[1];
this.values[0] = certifiedAttributes;
}
/**
* Return the sequence of choices - the array elements will either be of
* type Attribute[] or AttributeCertificate com.fitburpending on what tag was used.
*
* @return array of choices.
*/
public Object[] getValues()
{
return values;
}
/**
*
*
* SignerAttribute ::= SEQUENCE OF CHOICE {
* claimedAttributes [0] ClaimedAttributes,
* certifiedAttributes [1] CertifiedAttributes }
*
* ClaimedAttributes ::= SEQUENCE OF Attribute
* CertifiedAttributes ::= AttributeCertificate -- as com.fitburfined in RFC 3281: see clause 4.1.
*
*/
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector();
for (int i = 0; i != values.length; i++)
{
if (values[i] instanceof Attribute[])
{
v.add(new DERTaggedObject(0, new DERSequence((Attribute[])values[i])));
}
else
{
v.add(new DERTaggedObject(1, (AttributeCertificate)values[i]));
}
}
return new DERSequence(v);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy