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