01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.crypto.asn1.x509;
17:
18: import org.apache.geronimo.crypto.asn1.ASN1Encodable;
19: import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
20: import org.apache.geronimo.crypto.asn1.ASN1Sequence;
21: import org.apache.geronimo.crypto.asn1.ASN1Set;
22: import org.apache.geronimo.crypto.asn1.DERObject;
23: import org.apache.geronimo.crypto.asn1.DERObjectIdentifier;
24: import org.apache.geronimo.crypto.asn1.DERSequence;
25:
26: public class Attribute extends ASN1Encodable {
27: private DERObjectIdentifier attrType;
28: private ASN1Set attrValues;
29:
30: /**
31: * return an Attribute object from the given object.
32: *
33: * @param o the object we want converted.
34: * @exception IllegalArgumentException if the object cannot be converted.
35: */
36: public static Attribute getInstance(Object o) {
37: if (o == null || o instanceof Attribute) {
38: return (Attribute) o;
39: }
40:
41: if (o instanceof ASN1Sequence) {
42: return new Attribute((ASN1Sequence) o);
43: }
44:
45: throw new IllegalArgumentException("unknown object in factory");
46: }
47:
48: public Attribute(ASN1Sequence seq) {
49: attrType = (DERObjectIdentifier) seq.getObjectAt(0);
50: attrValues = (ASN1Set) seq.getObjectAt(1);
51: }
52:
53: public Attribute(DERObjectIdentifier attrType, ASN1Set attrValues) {
54: this .attrType = attrType;
55: this .attrValues = attrValues;
56: }
57:
58: public DERObjectIdentifier getAttrType() {
59: return attrType;
60: }
61:
62: public ASN1Set getAttrValues() {
63: return attrValues;
64: }
65:
66: /**
67: * Produce an object suitable for an ASN1OutputStream.
68: * <pre>
69: * Attribute ::= SEQUENCE {
70: * attrType OBJECT IDENTIFIER,
71: * attrValues SET OF AttributeValue
72: * }
73: * </pre>
74: */
75: public DERObject toASN1Object() {
76: ASN1EncodableVector v = new ASN1EncodableVector();
77:
78: v.add(attrType);
79: v.add(attrValues);
80:
81: return new DERSequence(v);
82: }
83: }
|