gnu.java.security

Class OID

Implemented Interfaces:
Cloneable, Comparable<T>, Serializable

public class OID
extends Object
implements Cloneable, Comparable<T>, Serializable

This immutable class represents an object identifier, or OID.

OIDs are represented as a series of hierarchical tokens, each of which is usually represented as a single, unsigned integer. The hierarchy works so that later tokens are considered within the group of earlier tokens. Thus, the OID for the Serpent block cipher, 1.3.6.1.4.1.11591.13.2, is maintained by the GNU project, whose OID is 1.3.6.1.4.1.11591 (which is, in turn, part of bigger, more general bodies; the topmost, 1, stands for the OIDs assigned by the International Standards Organization, ISO).

OIDs can be represented in a variety of ways, including the dotted-decimal form we use here.

OIDs may be relative, in which case the first two elements of the OID are omitted.

See Also:
Serialized Form

Constructor Summary

OID(byte[] encoded)
Construct a new OID from the given DER bytes.
OID(byte[] encoded, boolean relative)
Construct a new OID from the given DER bytes.
OID(int[] components)
Create a new OID from the given byte array.
OID(int[] components, boolean relative)
Create a new OID from the given byte array.
OID(InputStream derIn, int len)
Construct a new OID from the DER bytes in an input stream.
OID(InputStream derIn, int len, boolean relative)
Construct a new OID from the DER bytes in an input stream.
OID(String strRep)
Create a new OID from the given dotted-decimal representation.
OID(String strRep, boolean relative)
Create a new OID from the given dotted-decimal representation.

Method Summary

Object
clone()
Returns a copy of this OID.
int
compareTo(Object o)
Compares this OID to another.
boolean
equals(Object o)
Tests whether or not this OID equals another.
OID
getChild(int id)
byte[]
getDER()
Get the DER encoding of this OID, minus the tag and length fields.
int[]
getIDs()
Return the numeric IDs of this OID.
OID
getParent()
Get the parent OID of this OID.
OID
getRoot()
Get the root OID of this OID.
int
hashCode()
Computes a hash code for this OID.
boolean
isRelative()
String
toString()
Returns the value of this OID in dotted-decimal format.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

OID

public OID(byte[] encoded)
            throws IOException
Construct a new OID from the given DER bytes.
Parameters:
encoded - The DER encoded OID.
Throws:
IOException - If an error occurs reading the OID.

OID

public OID(byte[] encoded,
           boolean relative)
            throws IOException
Construct a new OID from the given DER bytes.
Parameters:
encoded - The encoded relative OID.
relative - The relative flag.

OID

public OID(int[] components)
Create a new OID from the given byte array. The argument (which can neither be null nor zero-length) is copied to prevent subsequent modification.
Parameters:
components - The numeric IDs.
Throws:
IllegalArgumentException - If components is null or empty.

OID

public OID(int[] components,
           boolean relative)
Create a new OID from the given byte array. The argument (which can neither be null nor zero-length) is copied to prevent subsequent modification.
Parameters:
components - The numeric IDs.
relative - The relative flag.
Throws:
IllegalArgumentException - If components is null or empty.

OID

public OID(InputStream derIn,
           int len)
            throws IOException
Construct a new OID from the DER bytes in an input stream. This method does not read the tag or the length field from the input stream, so the caller must supply the number of octets in this OID's encoded form.
Parameters:
derIn - The DER input stream.
len - The number of bytes in the encoded form.
Throws:
IOException - If an error occurs reading the OID.

OID

public OID(InputStream derIn,
           int len,
           boolean relative)
            throws IOException
Construct a new OID from the DER bytes in an input stream. This method does not read the tag or the length field from the input stream, so the caller must supply the number of octets in this OID's encoded form.
Parameters:
derIn - The DER input stream.
len - The number of bytes in the encoded form.
relative - The relative flag.
Throws:
IOException - If an error occurs reading the OID.

OID

public OID(String strRep)
Create a new OID from the given dotted-decimal representation.
Parameters:
strRep - The string representation of the OID.
Throws:
IllegalArgumentException - If the string does not contain at least one integer.
NumberFormatException - If the string does not contain only numbers and periods ('.').

OID

public OID(String strRep,
           boolean relative)
Create a new OID from the given dotted-decimal representation.
Parameters:
strRep - The string representation of the OID.
relative - The relative flag.
Throws:
IllegalArgumentException - If the string does not contain at least one integer.
NumberFormatException - If the string does not contain only numbers and periods ('.').

Method Details

clone

public Object clone()
Returns a copy of this OID.
Overrides:
clone in interface Object
Returns:
The copy.

compareTo

public int compareTo(Object o)
Compares this OID to another. The comparison is essentially lexicographic, where the two OIDs are compared until their first difference, then that difference is returned. If one OID is shorter, but all elements equal between the two for the shorter length, then the shorter OID is lesser than the longer.
Parameters:
o - The object to compare.
Returns:
An integer less than, equal to, or greater than zero if this object is less than, equal to, or greater than the argument.
Throws:
ClassCastException - If o is not an OID.

equals

public boolean equals(Object o)
Tests whether or not this OID equals another.
Overrides:
equals in interface Object
Returns:
Whether or not this OID equals the other.

getChild

public OID getChild(int id)

getDER

public byte[] getDER()
Get the DER encoding of this OID, minus the tag and length fields.
Returns:
The DER bytes.

getIDs

public int[] getIDs()
Return the numeric IDs of this OID. The value returned is copied to prevent modification.
Returns:
The IDs in a new integer array.

getParent

public OID getParent()
Get the parent OID of this OID. That is, if this OID is "1.2.3.4", then the parent OID will be "1.2.3". If this OID is a top-level OID, this method returns null.
Returns:
The parent OID, or null.

getRoot

public OID getRoot()
Get the root OID of this OID. That is, the first two components.
Returns:
The root OID.

hashCode

public int hashCode()
Computes a hash code for this OID.
Overrides:
hashCode in interface Object
Returns:
The hash code.

isRelative

public boolean isRelative()

toString

public String toString()
Returns the value of this OID in dotted-decimal format.
Overrides:
toString in interface Object
Returns:
The string representation.

OID.java -- numeric representation of an object identifier Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.