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.DEREncodable;
025    import org.apache.geronimo.util.asn1.DERObject;
026    import org.apache.geronimo.util.asn1.DERIA5String;
027    import org.apache.geronimo.util.asn1.DERObjectIdentifier;
028    import org.apache.geronimo.util.asn1.DERSequence;
029    
030    /**
031     * Policy qualifiers, used in the X509V3 CertificatePolicies
032     * extension.
033     *
034     * <pre>
035     *   PolicyQualifierInfo ::= SEQUENCE {
036     *       policyQualifierId  PolicyQualifierId,
037     *       qualifier          ANY DEFINED BY policyQualifierId }
038     * </pre>
039     */
040    public class PolicyQualifierInfo
041        extends ASN1Encodable
042    {
043       DERObjectIdentifier policyQualifierId;
044       DEREncodable qualifier;
045    
046       /**
047        * Creates a new <code>PolicyQualifierInfo</code> instance.
048        *
049        * @param policyQualifierId a <code>PolicyQualifierId</code> value
050        * @param qualifier the qualifier, defined by the above field.
051        */
052       public PolicyQualifierInfo (DERObjectIdentifier policyQualifierId,
053                                   DEREncodable qualifier)
054       {
055          this.policyQualifierId = policyQualifierId;
056          this.qualifier = qualifier;
057       }
058    
059       /**
060        * Creates a new <code>PolicyQualifierInfo</code> containing a
061        * cPSuri qualifier.
062        *
063        * @param cps the CPS (certification practice statement) uri as a
064        * <code>String</code>.
065        */
066       public PolicyQualifierInfo (String cps)
067       {
068          policyQualifierId = PolicyQualifierId.id_qt_cps;
069          qualifier = new DERIA5String (cps);
070       }
071    
072       /**
073        * Creates a new <code>PolicyQualifierInfo</code> instance.
074        *
075        * @param as <code>PolicyQualifierInfo</code> X509 structure
076        * encoded as an ASN1Sequence.
077        */
078       public PolicyQualifierInfo (ASN1Sequence as)
079       {
080            policyQualifierId = (DERObjectIdentifier) as.getObjectAt(0);
081            qualifier = as.getObjectAt(1);
082        }
083    
084       public static PolicyQualifierInfo getInstance (Object as)
085       {
086            if (as instanceof PolicyQualifierInfo)
087            {
088                return (PolicyQualifierInfo)as;
089            }
090            else if (as instanceof ASN1Sequence)
091            {
092                return new PolicyQualifierInfo((ASN1Sequence)as);
093            }
094    
095            throw new IllegalArgumentException("unknown object in getInstance.");
096       }
097    
098       /**
099        * Returns a DER-encodable representation of this instance.
100        *
101        * @return a <code>DERObject</code> value
102        */
103       public DERObject toASN1Object()
104       {
105          ASN1EncodableVector dev = new ASN1EncodableVector();
106          dev.add(policyQualifierId);
107          dev.add(qualifier);
108    
109          return new DERSequence(dev);
110       }
111    }