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 | Class and Description |
|---|---|
private static class |
Oid.OidFSAState
The OID FSA states.
|
| Modifier and Type | Field and Description |
|---|---|
private static BigInteger |
JOINT_ISO_ITU_T |
private byte[] |
oidBytes
A byte[] representation of an OID
|
private String |
oidString
The OID as a String
|
| Modifier | Constructor and Description |
|---|---|
private |
Oid(String oidString,
byte[] oidBytes)
Creates a new instance of Oid.
|
| Modifier and Type | Method and Description |
|---|---|
private static int |
convert(String oid,
byte[] buffer,
int start,
int nbDigits,
int posBuffer,
boolean isJointIsoItuT)
Convert a list of digits to a list of 7 bits bytes.
|
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. |
private static Oid.OidFSAState |
processStateA(String oid,
int pos)
Process state B
(A) --['.']
|
private static Oid.OidFSAState |
processStateB(String oid,
byte[] buffer,
int pos)
Process state B
(B) --['0']--> (D)
(B) --['1'..'3']--> (C)
(B) --['4'..'9']--> (E)
|
private static Oid.OidFSAState |
processStateC(String oid,
byte[] buffer,
int pos)
Process state C
(C) --['.']
|
private static Oid.OidFSAState |
processStateDE(String oid,
byte[] buffer,
int pos)
Process state D and E
(D) --['.']
|
private static Oid.OidFSAState |
processStateF(String oid,
int pos)
Process state F
(F) --['.']
|
private static Oid.OidFSAState |
processStateG(String oid,
byte[] buffer,
int pos)
Process state G
(G) --['0']--> (I)
(G) --['1'..'9']--> (H)
|
private static Oid.OidFSAState |
processStateH(String oid,
byte[] buffer,
int pos)
Process state H
(H) --['.']
|
private static Oid.OidFSAState |
processStateI(String oid,
byte[] buffer,
int pos)
Process state I
(I) --['.']
|
private static Oid.OidFSAState |
processStateJ(String oid,
byte[] buffer,
int bufferPos,
int pos)
Process state J
(J) --['.']
|
private static Oid.OidFSAState |
processStateK(String oid,
byte[] buffer,
int bufferPos,
int pos)
Process state J
(K) --['0']--> (M)
(K) --['1'..'9']--> (L)
|
private static Oid.OidFSAState |
processStateL(String oid,
byte[] buffer,
int bufferPos,
int pos)
Process state J
(L) --['.']
|
private static Oid.OidFSAState |
processStateM(String oid,
int pos)
Process state J
(M) --['.']
|
private static Oid.OidFSAState |
processStateStart(String oid,
byte[] buffer,
int pos)
Process state A
(Start) --['0','1']--> (A)
(start) --['2']--> (F)
|
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.
|
private byte[] oidBytes
private String oidString
private static final BigInteger JOINT_ISO_ITU_T
private Oid(String oidString, byte[] oidBytes)
oidString - The OID as a StringoidBytes - The OID as a byte[]public static Oid fromBytes(byte[] oidBytes) throws DecoderException
byte[].oidBytes - The encodedbyte[]DecoderException - When the OID is not validprivate static Oid.OidFSAState processStateStart(String oid, byte[] buffer, int pos) throws DecoderException
(Start) --['0','1']--> (A) (start) --['2']--> (F)
oid - The OID to checkbuffer - The buffer gathering the binary OIDpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateA(String oid, int pos) throws DecoderException
(A) --['.']--> (B)
oid - The OID to checkpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateB(String oid, byte[] buffer, int pos) throws DecoderException
(B) --['0']--> (D) (B) --['1'..'3']--> (C) (B) --['4'..'9']--> (E)
oid - The OID to checkbuffer - The buffer gathering the binary OIDpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateC(String oid, byte[] buffer, int pos) throws DecoderException
(C) --['.']--> (K) (C) --['0'..'9']--> (E)
oid - The OID to checkbuffer - The buffer gathering the binary OIDpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateDE(String oid, byte[] buffer, int pos) throws DecoderException
(D) --['.']--> (K) (E) --['.']--> (K)
oid - The OID to checkbuffer - The buffer gathering the binary OIDpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateF(String oid, int pos) throws DecoderException
(F) --['.']--> (G)
oid - The OID to checkpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateG(String oid, byte[] buffer, int pos) throws DecoderException
(G) --['0']--> (I) (G) --['1'..'9']--> (H)
oid - The OID to checkbuffer - The buffer gathering the binary OIDpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateH(String oid, byte[] buffer, int pos) throws DecoderException
(H) --['.']--> (K) (H) --['0'..'9']--> (J)
oid - The OID to checkbuffer - The buffer gathering the binary OIDpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateI(String oid, byte[] buffer, int pos) throws DecoderException
(I) --['.']--> (K)
oid - The OID to checkbuffer - The buffer gathering the binary OIDpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateJ(String oid, byte[] buffer, int bufferPos, int pos) throws DecoderException
(J) --['.']--> (K) (J) --['0'..'9']--> (J)
oid - The OID to checkbuffer - The buffer gathering the binary OIDbufferPos - The current position in the bufferpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateK(String oid, byte[] buffer, int bufferPos, int pos) throws DecoderException
(K) --['0']--> (M) (K) --['1'..'9']--> (L)
oid - The OID to checkbuffer - The buffer gathering the binary OIDbufferPos - The current position in the bufferpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateL(String oid, byte[] buffer, int bufferPos, int pos) throws DecoderException
(L) --['.']--> (K) (L) --['0'..'9']--> (L)
oid - The OID to checkbuffer - The buffer gathering the binary OIDbufferPos - The current position in the bufferpos - The position in the OID stringDecoderException - If the OID is invalidprivate static Oid.OidFSAState processStateM(String oid, int pos) throws DecoderException
(M) --['.']--> (K)
oid - The OID to checkpos - The position in the OID stringDecoderException - If the OID is invalidprivate static int convert(String oid, byte[] buffer, int start, int nbDigits, int posBuffer, boolean isJointIsoItuT)
oid - The OID to convertbuffer - The buffer gathering the binary OIDstart - The starting position in the OID stringnbDigits - Teh number of digits the OID hasposBuffer - The position in the bufferisJointIsoItuT - A flag set if we know the OID is a JointIsoItuT OIDpublic 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 String toString()
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–2022 The Apache Software Foundation. All rights reserved.