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