001package org.apache.commons.ssl.org.bouncycastle.asn1.cmp;
002
003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Encodable;
004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector;
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1ObjectIdentifier;
007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence;
009import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence;
010
011/**
012 * Example InfoTypeAndValue contents include, but are not limited
013 * to, the following (un-comment in this ASN.1 module and use as
014 * appropriate for a given environment):
015 * <pre>
016 *   id-it-caProtEncCert    OBJECT IDENTIFIER ::= {id-it 1}
017 *      CAProtEncCertValue      ::= CMPCertificate
018 *   id-it-signKeyPairTypes OBJECT IDENTIFIER ::= {id-it 2}
019 *     SignKeyPairTypesValue   ::= SEQUENCE OF AlgorithmIdentifier
020 *   id-it-encKeyPairTypes  OBJECT IDENTIFIER ::= {id-it 3}
021 *     EncKeyPairTypesValue    ::= SEQUENCE OF AlgorithmIdentifier
022 *   id-it-preferredSymmAlg OBJECT IDENTIFIER ::= {id-it 4}
023 *      PreferredSymmAlgValue   ::= AlgorithmIdentifier
024 *   id-it-caKeyUpdateInfo  OBJECT IDENTIFIER ::= {id-it 5}
025 *      CAKeyUpdateInfoValue    ::= CAKeyUpdAnnContent
026 *   id-it-currentCRL       OBJECT IDENTIFIER ::= {id-it 6}
027 *      CurrentCRLValue         ::= CertificateList
028 *   id-it-unsupportedOIDs  OBJECT IDENTIFIER ::= {id-it 7}
029 *      UnsupportedOIDsValue    ::= SEQUENCE OF OBJECT IDENTIFIER
030 *   id-it-keyPairParamReq  OBJECT IDENTIFIER ::= {id-it 10}
031 *      KeyPairParamReqValue    ::= OBJECT IDENTIFIER
032 *   id-it-keyPairParamRep  OBJECT IDENTIFIER ::= {id-it 11}
033 *      KeyPairParamRepValue    ::= AlgorithmIdentifer
034 *   id-it-revPassphrase    OBJECT IDENTIFIER ::= {id-it 12}
035 *      RevPassphraseValue      ::= EncryptedValue
036 *   id-it-implicitConfirm  OBJECT IDENTIFIER ::= {id-it 13}
037 *      ImplicitConfirmValue    ::= NULL
038 *   id-it-confirmWaitTime  OBJECT IDENTIFIER ::= {id-it 14}
039 *      ConfirmWaitTimeValue    ::= GeneralizedTime
040 *   id-it-origPKIMessage   OBJECT IDENTIFIER ::= {id-it 15}
041 *      OrigPKIMessageValue     ::= PKIMessages
042 *   id-it-suppLangTags     OBJECT IDENTIFIER ::= {id-it 16}
043 *      SuppLangTagsValue       ::= SEQUENCE OF UTF8String
044 *
045 * where
046 *
047 *   id-pkix OBJECT IDENTIFIER ::= {
048 *      iso(1) identified-organization(3)
049 *      dod(6) internet(1) security(5) mechanisms(5) pkix(7)}
050 * and
051 *      id-it   OBJECT IDENTIFIER ::= {id-pkix 4}
052 * </pre>
053 */
054public class InfoTypeAndValue
055    extends ASN1Object
056{
057    private ASN1ObjectIdentifier infoType;
058    private ASN1Encodable       infoValue;
059
060    private InfoTypeAndValue(ASN1Sequence seq)
061    {
062        infoType = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0));
063
064        if (seq.size() > 1)
065        {
066            infoValue = (ASN1Encodable)seq.getObjectAt(1);
067        }
068    }
069
070    public static InfoTypeAndValue getInstance(Object o)
071    {
072        if (o instanceof InfoTypeAndValue)
073        {
074            return (InfoTypeAndValue)o;
075        }
076
077        if (o != null)
078        {
079            return new InfoTypeAndValue(ASN1Sequence.getInstance(o));
080        }
081
082        return null;
083    }
084
085    public InfoTypeAndValue(
086        ASN1ObjectIdentifier infoType)
087    {
088        this.infoType = infoType;
089        this.infoValue = null;
090    }
091
092    public InfoTypeAndValue(
093        ASN1ObjectIdentifier infoType,
094        ASN1Encodable optionalValue)
095    {
096        this.infoType = infoType;
097        this.infoValue = optionalValue;
098    }
099
100    public ASN1ObjectIdentifier getInfoType()
101    {
102        return infoType;
103    }
104
105    public ASN1Encodable getInfoValue()
106    {
107        return infoValue;
108    }
109
110    /**
111     * <pre>
112     * InfoTypeAndValue ::= SEQUENCE {
113     *                         infoType               OBJECT IDENTIFIER,
114     *                         infoValue              ANY DEFINED BY infoType  OPTIONAL
115     * }
116     * </pre>
117     * @return a basic ASN.1 object representation.
118     */
119    public ASN1Primitive toASN1Primitive()
120    {
121        ASN1EncodableVector v = new ASN1EncodableVector();
122
123        v.add(infoType);
124
125        if (infoValue != null)
126        {
127            v.add(infoValue);
128        }
129
130        return new DERSequence(v);
131    }
132}