KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > ObjectDigestInfo


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.util.asn1.x509;
19
20 import org.apache.geronimo.util.asn1.ASN1Encodable;
21 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
22 import org.apache.geronimo.util.asn1.ASN1Sequence;
23 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
24 import org.apache.geronimo.util.asn1.DERBitString;
25 import org.apache.geronimo.util.asn1.DEREnumerated;
26 import org.apache.geronimo.util.asn1.DERObject;
27 import org.apache.geronimo.util.asn1.DERObjectIdentifier;
28 import org.apache.geronimo.util.asn1.DERSequence;
29 import org.apache.geronimo.util.asn1.x509.AlgorithmIdentifier;
30
31
32 public class ObjectDigestInfo
33     extends ASN1Encodable
34 {
35     DEREnumerated digestedObjectType;
36
37     DERObjectIdentifier otherObjectTypeID;
38
39     AlgorithmIdentifier digestAlgorithm;
40
41     DERBitString objectDigest;
42
43     public static ObjectDigestInfo getInstance(
44             Object JavaDoc obj)
45     {
46         if (obj == null || obj instanceof ObjectDigestInfo)
47         {
48             return (ObjectDigestInfo)obj;
49         }
50
51         if (obj instanceof ASN1Sequence)
52         {
53             return new ObjectDigestInfo((ASN1Sequence)obj);
54         }
55
56         throw new IllegalArgumentException JavaDoc("illegal object in getInstance: " + obj.getClass().getName());
57     }
58
59     public static ObjectDigestInfo getInstance(
60         ASN1TaggedObject obj,
61         boolean explicit)
62     {
63         return getInstance(ASN1Sequence.getInstance(obj, explicit));
64     }
65
66     public ObjectDigestInfo(ASN1Sequence seq)
67     {
68         digestedObjectType = DEREnumerated.getInstance(seq.getObjectAt(0));
69
70         int offset = 0;
71
72         if (seq.size() == 4)
73         {
74             otherObjectTypeID = DERObjectIdentifier.getInstance(seq.getObjectAt(1));
75             offset++;
76         }
77
78         digestAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1 + offset));
79
80         objectDigest = new DERBitString(seq.getObjectAt(2 + offset));
81     }
82
83     public DEREnumerated getDigestedObjectType()
84     {
85         return digestedObjectType;
86     }
87
88     public DERObjectIdentifier getOtherObjectTypeID()
89     {
90         return otherObjectTypeID;
91     }
92
93     public AlgorithmIdentifier getDigestAlgorithm()
94     {
95         return digestAlgorithm;
96     }
97
98     public DERBitString getObjectDigest()
99     {
100         return objectDigest;
101     }
102
103     /**
104      * Produce an object suitable for an ASN1OutputStream.
105      *
106      * <pre>
107      *
108      * ObjectDigestInfo ::= SEQUENCE {
109      * digestedObjectType ENUMERATED {
110      * publicKey (0),
111      * publicKeyCert (1),
112      * otherObjectTypes (2) },
113      * -- otherObjectTypes MUST NOT
114      * -- be used in this profile
115      * otherObjectTypeID OBJECT IDENTIFIER OPTIONAL,
116      * digestAlgorithm AlgorithmIdentifier,
117      * objectDigest BIT STRING
118      * }
119      *
120      * </pre>
121      */

122     public DERObject toASN1Object()
123     {
124         ASN1EncodableVector v = new ASN1EncodableVector();
125
126         v.add(digestedObjectType);
127
128         if (otherObjectTypeID != null)
129         {
130             v.add(otherObjectTypeID);
131         }
132
133         v.add(digestAlgorithm);
134         v.add(objectDigest);
135
136         return new DERSequence(v);
137     }
138 }
139
Popular Tags