001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package org.apache.geronimo.util.asn1.x509;
020
021 import org.apache.geronimo.util.asn1.ASN1Encodable;
022 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
023 import org.apache.geronimo.util.asn1.ASN1Sequence;
024 import org.apache.geronimo.util.asn1.ASN1Set;
025 import org.apache.geronimo.util.asn1.DERObject;
026 import org.apache.geronimo.util.asn1.DERObjectIdentifier;
027 import org.apache.geronimo.util.asn1.DERSequence;
028
029 public class Attribute
030 extends ASN1Encodable
031 {
032 private DERObjectIdentifier attrType;
033 private ASN1Set attrValues;
034
035 /**
036 * return an Attribute object from the given object.
037 *
038 * @param o the object we want converted.
039 * @exception IllegalArgumentException if the object cannot be converted.
040 */
041 public static Attribute getInstance(
042 Object o)
043 {
044 if (o == null || o instanceof Attribute)
045 {
046 return (Attribute)o;
047 }
048
049 if (o instanceof ASN1Sequence)
050 {
051 return new Attribute((ASN1Sequence)o);
052 }
053
054 throw new IllegalArgumentException("unknown object in factory");
055 }
056
057 public Attribute(
058 ASN1Sequence seq)
059 {
060 attrType = (DERObjectIdentifier)seq.getObjectAt(0);
061 attrValues = (ASN1Set)seq.getObjectAt(1);
062 }
063
064 public Attribute(
065 DERObjectIdentifier attrType,
066 ASN1Set attrValues)
067 {
068 this.attrType = attrType;
069 this.attrValues = attrValues;
070 }
071
072 public DERObjectIdentifier getAttrType()
073 {
074 return attrType;
075 }
076
077 public ASN1Set getAttrValues()
078 {
079 return attrValues;
080 }
081
082 /**
083 * Produce an object suitable for an ASN1OutputStream.
084 * <pre>
085 * Attribute ::= SEQUENCE {
086 * attrType OBJECT IDENTIFIER,
087 * attrValues SET OF AttributeValue
088 * }
089 * </pre>
090 */
091 public DERObject toASN1Object()
092 {
093 ASN1EncodableVector v = new ASN1EncodableVector();
094
095 v.add(attrType);
096 v.add(attrValues);
097
098 return new DERSequence(v);
099 }
100 }