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.DERBitString;
025    import org.apache.geronimo.util.asn1.DERObject;
026    import org.apache.geronimo.util.asn1.DERSequence;
027    
028    public class AttributeCertificate
029        extends ASN1Encodable
030    {
031        AttributeCertificateInfo    acinfo;
032        AlgorithmIdentifier         signatureAlgorithm;
033        DERBitString                signatureValue;
034    
035        /**
036         * @param obj
037         * @return an AttributeCertificate object
038         */
039        public static AttributeCertificate getInstance(Object obj)
040        {
041            if (obj instanceof AttributeCertificate)
042            {
043                return (AttributeCertificate)obj;
044            }
045            else if (obj instanceof ASN1Sequence)
046            {
047                return new AttributeCertificate((ASN1Sequence)obj);
048            }
049    
050            throw new IllegalArgumentException("unknown object in factory");
051        }
052    
053        public AttributeCertificate(
054            AttributeCertificateInfo    acinfo,
055            AlgorithmIdentifier         signatureAlgorithm,
056            DERBitString                signatureValue)
057        {
058            this.acinfo = acinfo;
059            this.signatureAlgorithm = signatureAlgorithm;
060            this.signatureValue = signatureValue;
061        }
062    
063        public AttributeCertificate(
064            ASN1Sequence    seq)
065        {
066            this.acinfo = AttributeCertificateInfo.getInstance(seq.getObjectAt(0));
067            this.signatureAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
068            this.signatureValue = DERBitString.getInstance(seq.getObjectAt(2));
069        }
070    
071        public AttributeCertificateInfo getAcinfo()
072        {
073            return acinfo;
074        }
075    
076        public AlgorithmIdentifier getSignatureAlgorithm()
077        {
078            return signatureAlgorithm;
079        }
080    
081        public DERBitString getSignatureValue()
082        {
083            return signatureValue;
084        }
085    
086        /**
087         * Produce an object suitable for an ASN1OutputStream.
088         * <pre>
089         *  AttributeCertificate ::= SEQUENCE {
090         *       acinfo               AttributeCertificateInfo,
091         *       signatureAlgorithm   AlgorithmIdentifier,
092         *       signatureValue       BIT STRING
093         *  }
094         * </pre>
095         */
096        public DERObject toASN1Object()
097        {
098            ASN1EncodableVector  v = new ASN1EncodableVector();
099    
100            v.add(acinfo);
101            v.add(signatureAlgorithm);
102            v.add(signatureValue);
103    
104            return new DERSequence(v);
105        }
106    }