01: package org.bouncycastle.asn1.esf;
02:
03: import org.bouncycastle.asn1.*;
04: import org.bouncycastle.asn1.x509.AttributeCertificate;
05:
06: public class SignerAttribute extends ASN1Encodable {
07: private ASN1Sequence claimedAttributes;
08: private AttributeCertificate certifiedAttributes;
09:
10: public static SignerAttribute getInstance(Object o) {
11: if (o == null || o instanceof SignerAttribute) {
12: return (SignerAttribute) o;
13: } else if (o instanceof ASN1Sequence) {
14: return new SignerAttribute(o);
15: }
16:
17: throw new IllegalArgumentException(
18: "unknown object in 'SignerAttribute' factory: "
19: + o.getClass().getName() + ".");
20: }
21:
22: private SignerAttribute(Object o) {
23: ASN1Sequence seq = (ASN1Sequence) o;
24: DERTaggedObject taggedObject = (DERTaggedObject) seq
25: .getObjectAt(0);
26: if (taggedObject.getTagNo() == 0) {
27: claimedAttributes = ASN1Sequence.getInstance(taggedObject,
28: true);
29: } else if (taggedObject.getTagNo() == 1) {
30: certifiedAttributes = AttributeCertificate
31: .getInstance(taggedObject);
32: } else {
33: throw new IllegalArgumentException("illegal tag.");
34: }
35: }
36:
37: public SignerAttribute(ASN1Sequence claimedAttributes) {
38: this .claimedAttributes = claimedAttributes;
39: }
40:
41: public SignerAttribute(AttributeCertificate certifiedAttributes) {
42: this .certifiedAttributes = certifiedAttributes;
43: }
44:
45: public ASN1Sequence getClaimedAttributes() {
46: return claimedAttributes;
47: }
48:
49: public AttributeCertificate getCertifiedAttributes() {
50: return certifiedAttributes;
51: }
52:
53: /**
54: *
55: * <pre>
56: * SignerAttribute ::= SEQUENCE OF CHOICE {
57: * claimedAttributes [0] ClaimedAttributes,
58: * certifiedAttributes [1] CertifiedAttributes }
59: *
60: * ClaimedAttributes ::= SEQUENCE OF Attribute
61: * CertifiedAttributes ::= AttributeCertificate -- as defined in RFC 3281: see clause 4.1.
62: * </pre>
63: */
64: public DERObject toASN1Object() {
65: ASN1EncodableVector v = new ASN1EncodableVector();
66:
67: if (claimedAttributes != null) {
68: v.add(new DERTaggedObject(0, claimedAttributes));
69: } else {
70: v.add(new DERTaggedObject(1, certifiedAttributes));
71: }
72:
73: return new DERSequence(v);
74: }
75: }
|