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.crypto.asn1.x509;
019    
020    import org.apache.geronimo.crypto.asn1.ASN1Encodable;
021    import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
022    import org.apache.geronimo.crypto.asn1.ASN1Sequence;
023    import org.apache.geronimo.crypto.asn1.DERObject;
024    import org.apache.geronimo.crypto.asn1.DERObjectIdentifier;
025    import org.apache.geronimo.crypto.asn1.DERSequence;
026    
027    /**
028     * The AuthorityInformationAccess object.
029     * <pre>
030     * id-pe-authorityInfoAccess OBJECT IDENTIFIER ::= { id-pe 1 }
031     *
032     * AuthorityInfoAccessSyntax  ::=
033     *      SEQUENCE SIZE (1..MAX) OF AccessDescription
034     * AccessDescription  ::=  SEQUENCE {
035     *       accessMethod          OBJECT IDENTIFIER,
036     *       accessLocation        GeneralName  }
037     *
038     * id-ad OBJECT IDENTIFIER ::= { id-pkix 48 }
039     * id-ad-caIssuers OBJECT IDENTIFIER ::= { id-ad 2 }
040     * id-ad-ocsp OBJECT IDENTIFIER ::= { id-ad 1 }
041     * </pre>
042     */
043    public class AuthorityInformationAccess
044        extends ASN1Encodable
045    {
046        private AccessDescription[]    descriptions;
047    
048        public static AuthorityInformationAccess getInstance(
049            Object  obj)
050        {
051            if (obj instanceof AuthorityInformationAccess)
052            {
053                return (AuthorityInformationAccess)obj;
054            }
055            else if (obj instanceof ASN1Sequence)
056            {
057                return new AuthorityInformationAccess((ASN1Sequence)obj);
058            }
059    
060            throw new IllegalArgumentException("unknown object in factory");
061        }
062    
063        public AuthorityInformationAccess(
064            ASN1Sequence   seq)
065        {
066            descriptions = new AccessDescription[seq.size()];
067    
068            for (int i = 0; i != seq.size(); i++)
069            {
070                descriptions[i] = AccessDescription.getInstance(seq.getObjectAt(i));
071            }
072        }
073    
074        /**
075         * create an AuthorityInformationAccess with the oid and location provided.
076         */
077        public AuthorityInformationAccess(
078            DERObjectIdentifier oid,
079            GeneralName location)
080        {
081            descriptions = new AccessDescription[1];
082    
083            descriptions[0] = new AccessDescription(oid, location);
084        }
085    
086    
087        /**
088         *
089         * @return the access descriptions contained in this object.
090         */
091        public AccessDescription[] getAccessDescriptions()
092        {
093            return descriptions;
094        }
095    
096        public DERObject toASN1Object()
097        {
098            ASN1EncodableVector vec = new ASN1EncodableVector();
099    
100            for (int i = 0; i != descriptions.length; i++)
101            {
102                vec.add(descriptions[i]);
103            }
104    
105            return new DERSequence(vec);
106        }
107    
108        public String toString()
109        {
110            return ("AuthorityInformationAccess: Oid(" + this.descriptions[0].getAccessMethod().getId() + ")");
111        }
112    }