~brian-thomason/+junk/bouncycastle

« back to all changes in this revision

Viewing changes to src/org/bouncycastle/asn1/cmp/InfoTypeAndValue.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:20:32 UTC
  • Revision ID: brian.thomason@canonical.com-20111220172032-rdtm13jgdxtksacr
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.bouncycastle.asn1.cmp;
 
2
 
 
3
import org.bouncycastle.asn1.ASN1Encodable;
 
4
import org.bouncycastle.asn1.ASN1EncodableVector;
 
5
import org.bouncycastle.asn1.ASN1Sequence;
 
6
import org.bouncycastle.asn1.DERObject;
 
7
import org.bouncycastle.asn1.DERObjectIdentifier;
 
8
import org.bouncycastle.asn1.DERSequence;
 
9
 
 
10
/**
 
11
 * Example InfoTypeAndValue contents include, but are not limited
 
12
 * to, the following (un-comment in this ASN.1 module and use as
 
13
 * appropriate for a given environment):
 
14
 * <pre>
 
15
 *   id-it-caProtEncCert    OBJECT IDENTIFIER ::= {id-it 1}
 
16
 *      CAProtEncCertValue      ::= CMPCertificate
 
17
 *   id-it-signKeyPairTypes OBJECT IDENTIFIER ::= {id-it 2}
 
18
 *     SignKeyPairTypesValue   ::= SEQUENCE OF AlgorithmIdentifier
 
19
 *   id-it-encKeyPairTypes  OBJECT IDENTIFIER ::= {id-it 3}
 
20
 *     EncKeyPairTypesValue    ::= SEQUENCE OF AlgorithmIdentifier
 
21
 *   id-it-preferredSymmAlg OBJECT IDENTIFIER ::= {id-it 4}
 
22
 *      PreferredSymmAlgValue   ::= AlgorithmIdentifier
 
23
 *   id-it-caKeyUpdateInfo  OBJECT IDENTIFIER ::= {id-it 5}
 
24
 *      CAKeyUpdateInfoValue    ::= CAKeyUpdAnnContent
 
25
 *   id-it-currentCRL       OBJECT IDENTIFIER ::= {id-it 6}
 
26
 *      CurrentCRLValue         ::= CertificateList
 
27
 *   id-it-unsupportedOIDs  OBJECT IDENTIFIER ::= {id-it 7}
 
28
 *      UnsupportedOIDsValue    ::= SEQUENCE OF OBJECT IDENTIFIER
 
29
 *   id-it-keyPairParamReq  OBJECT IDENTIFIER ::= {id-it 10}
 
30
 *      KeyPairParamReqValue    ::= OBJECT IDENTIFIER
 
31
 *   id-it-keyPairParamRep  OBJECT IDENTIFIER ::= {id-it 11}
 
32
 *      KeyPairParamRepValue    ::= AlgorithmIdentifer
 
33
 *   id-it-revPassphrase    OBJECT IDENTIFIER ::= {id-it 12}
 
34
 *      RevPassphraseValue      ::= EncryptedValue
 
35
 *   id-it-implicitConfirm  OBJECT IDENTIFIER ::= {id-it 13}
 
36
 *      ImplicitConfirmValue    ::= NULL
 
37
 *   id-it-confirmWaitTime  OBJECT IDENTIFIER ::= {id-it 14}
 
38
 *      ConfirmWaitTimeValue    ::= GeneralizedTime
 
39
 *   id-it-origPKIMessage   OBJECT IDENTIFIER ::= {id-it 15}
 
40
 *      OrigPKIMessageValue     ::= PKIMessages
 
41
 *   id-it-suppLangTags     OBJECT IDENTIFIER ::= {id-it 16}
 
42
 *      SuppLangTagsValue       ::= SEQUENCE OF UTF8String
 
43
 *
 
44
 * where
 
45
 *
 
46
 *   id-pkix OBJECT IDENTIFIER ::= {
 
47
 *      iso(1) identified-organization(3)
 
48
 *      dod(6) internet(1) security(5) mechanisms(5) pkix(7)}
 
49
 * and
 
50
 *      id-it   OBJECT IDENTIFIER ::= {id-pkix 4}
 
51
 * </pre>
 
52
 */
 
53
public class InfoTypeAndValue
 
54
    extends ASN1Encodable
 
55
{
 
56
    private DERObjectIdentifier infoType;
 
57
    private ASN1Encodable       infoValue;
 
58
 
 
59
    private InfoTypeAndValue(ASN1Sequence seq)
 
60
    {
 
61
        infoType = DERObjectIdentifier.getInstance(seq.getObjectAt(0));
 
62
 
 
63
        if (seq.size() > 1)
 
64
        {
 
65
            infoValue = (ASN1Encodable)seq.getObjectAt(1);
 
66
        }
 
67
    }
 
68
 
 
69
    public static InfoTypeAndValue getInstance(Object o)
 
70
    {
 
71
        if (o instanceof InfoTypeAndValue)
 
72
        {
 
73
            return (InfoTypeAndValue)o;
 
74
        }
 
75
 
 
76
        if (o instanceof ASN1Sequence)
 
77
        {
 
78
            return new InfoTypeAndValue((ASN1Sequence)o);
 
79
        }
 
80
 
 
81
        throw new IllegalArgumentException("Invalid object: " + o.getClass().getName());
 
82
    }
 
83
 
 
84
    public InfoTypeAndValue(
 
85
        DERObjectIdentifier infoType)
 
86
    {
 
87
        this.infoType = infoType;
 
88
        this.infoValue = null;
 
89
    }
 
90
 
 
91
    public InfoTypeAndValue(
 
92
        DERObjectIdentifier infoType,
 
93
        ASN1Encodable optionalValue)
 
94
    {
 
95
        this.infoType = infoType;
 
96
        this.infoValue = optionalValue;
 
97
    }
 
98
 
 
99
    public DERObjectIdentifier getInfoType()
 
100
    {
 
101
        return infoType;
 
102
    }
 
103
 
 
104
    public ASN1Encodable getInfoValue()
 
105
    {
 
106
        return infoValue;
 
107
    }
 
108
 
 
109
    /**
 
110
     * <pre>
 
111
     * InfoTypeAndValue ::= SEQUENCE {
 
112
     *                         infoType               OBJECT IDENTIFIER,
 
113
     *                         infoValue              ANY DEFINED BY infoType  OPTIONAL
 
114
     * }
 
115
     * </pre>
 
116
     * @return a basic ASN.1 object representation.
 
117
     */
 
118
    public DERObject toASN1Object()
 
119
    {
 
120
        ASN1EncodableVector v = new ASN1EncodableVector();
 
121
 
 
122
        v.add(infoType);
 
123
 
 
124
        if (infoValue != null)
 
125
        {
 
126
            v.add(infoValue);
 
127
        }
 
128
 
 
129
        return new DERSequence(v);
 
130
    }
 
131
}