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