public final class Oid extends Object
String
, and encoded byte[]
representations.
The encoding of OID values is performed according to itu X.690 section 8.19. Specifically:
8.19.2 The contents octets shall be an (ordered) list of encodings of subidentifiers (see 8.19.3 and 8.19.4) concatenated together. Each subidentifier is represented as a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero; bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the subidentifier. Conceptually, these groups of bits are concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of the last octet. The subidentifier shall be encoded in the fewest possible octets, that is, the leading octet of the subidentifier shall not have the value 0x80.
8.19.3 The number of subidentifiers (N) shall be one less than the number of object identifier components in the object identifier value being encoded.
8.19.4 The numerical value of the first subidentifier is derived
from the values of the first two object identifier components in the object
identifier value being encoded, using the formula:
(X*40) + Y
where X is the value of the first object identifier component and Y is the
value of the second object identifier component. NOTE – This packing of
the first two object identifier components recognizes that only three values
are allocated from the root node, and at most 39 subsequent values from nodes
reached by X = 0 and X = 1.
For example, the OID "2.12.3456.7" would be turned into a list of 3 values:
[((2*40)+12), 3456, 7]
. The first of which,
92
, would be encoded as the bytes 0x5C
, the second
would be [0x9B, 0x00]
, and the third as 0x07
giving the final encoding [0x5C, 0x9B, 0x00, 0x07]
.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
static Oid |
fromBytes(byte[] oidBytes)
Decodes an OID from a
byte[] . |
static Oid |
fromString(String oidString)
Returns an OID object representing
oidString . |
int |
getEncodedLength()
Returns the length of the encoded
byte[] representation. |
int |
hashCode() |
static boolean |
isOid(String oidString)
Returns true if
oidString is a valid string representation
of an OID. |
byte[] |
toBytes()
Returns the
byte[] representation of the OID. |
String |
toString()
Returns the string representation of the OID.
|
void |
writeBytesTo(ByteBuffer buffer)
Writes the bytes respresenting this OID to the provided buffer.
|
void |
writeBytesTo(OutputStream outputStream)
Writes the bytes respresenting this OID to the provided stream.
|
public static Oid fromBytes(byte[] oidBytes) throws DecoderException
byte[]
.oidBytes
- The encodedbyte[]
DecoderException
- When the OID is not validpublic static Oid fromString(String oidString) throws DecoderException
oidString
.oidString
- The string representation of the OIDDecoderException
- When the OID is not validpublic int getEncodedLength()
byte[]
representation.public static boolean isOid(String oidString)
oidString
is a valid string representation
of an OID. This method simply calls fromString(String)
and
returns true if no exception was thrown. As such, it should not be used
in an attempt to check if a string is a valid OID before calling
fromString(String)
.oidString
- The string to testoidString
is validpublic byte[] toBytes()
byte[]
representation of the OID. The
byte[]
that is returned is copied from the internal
value so as to preserve the immutability of an OID object. If the
output of a call to this method is intended to be written to a stream,
the writeBytesTo(OutputStream)
should be used instead as it will
avoid creating this copy.byte[]
representation of the OID.public void writeBytesTo(ByteBuffer buffer)
toBytes()
method in order
to prevent the creation of copies of the actual byte[]
.buffer
- The buffer to write the bytes intopublic void writeBytesTo(OutputStream outputStream) throws IOException
toBytes()
method in order
to prevent the creation of copies of the actual byte[]
.outputStream
- The stream to write the bytes toIOException
- When we can't write the OID into a StreamCopyright © 2003–2020 The Apache Software Foundation. All rights reserved.