001package org.apache.commons.ssl.org.bouncycastle.asn1.x509;
002
003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector;
004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1ObjectIdentifier;
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence;
008import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence;
009
010/**
011 * The AccessDescription object.
012 * <pre>
013 * AccessDescription  ::=  SEQUENCE {
014 *       accessMethod          OBJECT IDENTIFIER,
015 *       accessLocation        GeneralName  }
016 * </pre>
017 */
018public class AccessDescription
019    extends ASN1Object
020{
021    public final static ASN1ObjectIdentifier id_ad_caIssuers = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.48.2");
022    
023    public final static ASN1ObjectIdentifier id_ad_ocsp = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.48.1");
024        
025    ASN1ObjectIdentifier accessMethod = null;
026    GeneralName accessLocation = null;
027
028    public static AccessDescription getInstance(
029        Object  obj)
030    {
031        if (obj instanceof AccessDescription)
032        {
033            return (AccessDescription)obj;
034        }
035        else if (obj != null)
036        {
037            return new AccessDescription(ASN1Sequence.getInstance(obj));
038        }
039
040        return null;
041    }
042 
043    private AccessDescription(
044        ASN1Sequence   seq)
045    {
046        if (seq.size() != 2) 
047        {
048            throw new IllegalArgumentException("wrong number of elements in sequence");
049        }
050        
051        accessMethod = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0));
052        accessLocation = GeneralName.getInstance(seq.getObjectAt(1));
053    }
054
055    /**
056     * create an AccessDescription with the oid and location provided.
057     */
058    public AccessDescription(
059        ASN1ObjectIdentifier oid,
060        GeneralName location)
061    {
062        accessMethod = oid;
063        accessLocation = location;
064    }
065
066    /**
067     * 
068     * @return the access method.
069     */
070    public ASN1ObjectIdentifier getAccessMethod()
071    {
072        return accessMethod;
073    }
074    
075    /**
076     * 
077     * @return the access location
078     */
079    public GeneralName getAccessLocation()
080    {
081        return accessLocation;
082    }
083    
084    public ASN1Primitive toASN1Primitive()
085    {
086        ASN1EncodableVector accessDescription  = new ASN1EncodableVector();
087        
088        accessDescription.add(accessMethod);
089        accessDescription.add(accessLocation);
090
091        return new DERSequence(accessDescription);
092    }
093
094    public String toString()
095    {
096        return ("AccessDescription: Oid(" + this.accessMethod.getId() + ")");
097    }
098}