API Overview API Index Package Overview Direct link to this page
JDK 1.6
  org.ietf.jgss. Oid View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

/*
 * @(#)Oid.java	1.10 06/06/22
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
 
package org.ietf.jgss;

import java.io.InputStream;
import java.io.IOException;
import sun.security.util.DerValue;
import sun.security.util.DerOutputStream;
import sun.security.util.ObjectIdentifier;

/** 
 * This class represents Universal Object Identifiers (Oids) and their
 * associated operations.<p>
 *
 * Oids are hierarchically globally-interpretable identifiers used
 * within the GSS-API framework to identify mechanisms and name formats.<p>
 *
 * The structure and encoding of Oids is defined in ISOIEC-8824 and
 * ISOIEC-8825.  For example the Oid representation of Kerberos V5
 * mechanism is "1.2.840.113554.1.2.2"<p>
 *
 * The GSSName name class contains public static Oid objects
 * representing the standard name types defined in GSS-API.
 *
 * @author Mayank Upadhyay
 * @version 1.10, 06/22/06
 * @since 1.4
 */
public class Oid {

    private ObjectIdentifier oid;
    private byte[] derEncoding;

    /** 
     * Constructs an Oid object from a string representation of its
     * integer components.
     * 
     * @param strOid the dot separated string representation of the oid.
     * For instance, "1.2.840.113554.1.2.2".
     * @exception GSSException may be thrown when the string is incorrectly 
     *     formatted
     */
    public Oid(String strOid) throws GSSException {

        try {
	    oid = new ObjectIdentifier(strOid);
	    derEncoding = null;
        } catch (Exception e) {
            throw new GSSException(GSSException.FAILURE, 
                          "Improperly formatted Object Identifier String - "
                          + strOid);  
	}
    }

    /** 
     * Creates an Oid object from its ASN.1 DER encoding.  This refers to
     * the full encoding including tag and length.  The structure and
     * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
     * method is identical in functionality to its byte array counterpart.
     * 
     * @param derOid stream containing the DER encoded oid
     * @exception GSSException may be thrown when the DER encoding does not 
     *  follow the prescribed format.
     */
    public Oid(InputStream derOid) throws GSSException {
	try {
	    DerValue derVal = new DerValue(derOid);
	    derEncoding = derVal.toByteArray();
	    oid = derVal.getOID();
	} catch (IOException e) {
            throw new GSSException(GSSException.FAILURE, 
                          "Improperly formatted ASN.1 DER encoding for Oid");
	}
    }


    /** 
     * Creates an Oid object from its ASN.1 DER encoding.  This refers to
     * the full encoding including tag and length.  The structure and
     * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
     * method is identical in functionality to its InputStream conterpart.
     * 
     * @param data byte array containing the DER encoded oid
     * @exception GSSException may be thrown when the DER encoding does not 
     *     follow the prescribed format.
     */
    public Oid(byte [] data) throws GSSException {
	try {
	    DerValue derVal = new DerValue(data);
	    derEncoding = derVal.toByteArray();
	    oid = derVal.getOID();
	} catch (IOException e) {
            throw new GSSException(GSSException.FAILURE, 
                          "Improperly formatted ASN.1 DER encoding for Oid");
	}
    }

    /** 
     * Only for calling by initializators used with declarations.
     * 
     * @param strOid 
     */
    static Oid getInstance(String strOid) {
        Oid retVal = null;
        try {
            retVal =  new Oid(strOid); 
        } catch (GSSException e) {
            // squelch it!
        }
        return retVal;
    }
 
    /** 
     * Returns a string representation of the oid's integer components
     * in dot separated notation.
     * 
     * @return string representation in the following format: "1.2.3.4.5"
     */
    public String toString() {
	return oid.toString();
    }

    /** 
     * Tests if two Oid objects represent the same Object identifier
     * value.
     *
     * @return <code>true</code> if the two Oid objects represent the same
     * value, <code>false</code> otherwise.
     * @param other the Oid object that has to be compared to this one
     */
    public boolean equals(Object other) {

        //check if both reference the same object
        if (this == other)
            return (true);

	if (other instanceof Oid)
	    return this.oid.equals(((Oid) other).oid);
	else if (other instanceof ObjectIdentifier)
	    return this.oid.equals(other);
	else
	    return false;
    }

    
    /** 
     * Returns the full ASN.1 DER encoding for this oid object, which
     * includes the tag and length.
     * 
     * @return byte array containing the DER encoding of this oid object.
     * @exception GSSException may be thrown when the oid can't be encoded
     */
    public byte[] getDER() throws GSSException {
    
        if (derEncoding == null) {
	    DerOutputStream dout = new DerOutputStream();
	    try {
		dout.putOID(oid);
	    } catch (IOException e) {
		throw new GSSException(GSSException.FAILURE, e.getMessage());
	    }
	    derEncoding = dout.toByteArray();
	}

        return (byte[])derEncoding.clone();
    }
    
    /** 
     * A utility method to test if this Oid value is contained within the
     * supplied Oid array.
     *
     * @param oids the array of Oid's to search
     * @return true if the array contains this Oid value, false otherwise
     */
    public boolean containedIn(Oid[] oids) {
    
        for (int i = 0; i < oids.length; i++) {
            if (oids[i].equals(this))
                return (true);
        }
    
        return (false);
    }
    

    /**
     * Returns a hashcode value for this Oid.
     *
     * @return a hashCode value
     */
    public int hashCode() {
	return oid.hashCode();
    }
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar