Class Oid
- java.lang.Object
-
- org.apache.directory.api.asn1.util.Oid
-
public final class Oid extends Object
An immutable representation of an object identifier that provides conversion between theirString, and encodedbyte[]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 bytes0x5C, the second would be[0x9B, 0x00], and the third as0x07giving the final encoding[0x5C, 0x9B, 0x00, 0x07].- Author:
- Apache Directory Project
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classOid.OidFSAStateThe OID FSA states.
-
Field Summary
Fields Modifier and Type Field Description private static BigIntegerJOINT_ISO_ITU_Tprivate byte[]oidBytesA byte[] representation of an OIDprivate StringoidStringThe OID as a String
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static intconvert(String oid, byte[] buffer, int start, int nbDigits, int posBuffer, boolean isJointIsoItuT)Convert a list of digits to a list of 7 bits bytes.booleanequals(Object other)static OidfromBytes(byte[] oidBytes)Decodes an OID from abyte[].static OidfromString(String oidString)Returns an OID object representingoidString.intgetEncodedLength()Returns the length of the encodedbyte[]representation.inthashCode()static booleanisOid(String oidString)Returns true ifoidStringis a valid string representation of an OID.private static Oid.OidFSAStateprocessStateA(String oid, int pos)Process state Bprivate static Oid.OidFSAStateprocessStateB(String oid, byte[] buffer, int pos)Process state Bprivate static Oid.OidFSAStateprocessStateC(String oid, byte[] buffer, int pos)Process state Cprivate static Oid.OidFSAStateprocessStateDE(String oid, byte[] buffer, int pos)Process state D and Eprivate static Oid.OidFSAStateprocessStateF(String oid, int pos)Process state Fprivate static Oid.OidFSAStateprocessStateG(String oid, byte[] buffer, int pos)Process state Gprivate static Oid.OidFSAStateprocessStateH(String oid, byte[] buffer, int pos)Process state Hprivate static Oid.OidFSAStateprocessStateI(String oid, byte[] buffer, int pos)Process state Iprivate static Oid.OidFSAStateprocessStateJ(String oid, byte[] buffer, int bufferPos, int pos)Process state Jprivate static Oid.OidFSAStateprocessStateK(String oid, byte[] buffer, int bufferPos, int pos)Process state Jprivate static Oid.OidFSAStateprocessStateL(String oid, byte[] buffer, int bufferPos, int pos)Process state Jprivate static Oid.OidFSAStateprocessStateM(String oid, int pos)Process state Jprivate static Oid.OidFSAStateprocessStateStart(String oid, byte[] buffer, int pos)Process state Abyte[]toBytes()Returns thebyte[]representation of the OID.StringtoString()Returns the string representation of the OID.voidwriteBytesTo(OutputStream outputStream)Writes the bytes respresenting this OID to the provided stream.voidwriteBytesTo(ByteBuffer buffer)Writes the bytes respresenting this OID to the provided buffer.
-
-
-
Field Detail
-
oidBytes
private byte[] oidBytes
A byte[] representation of an OID
-
oidString
private String oidString
The OID as a String
-
JOINT_ISO_ITU_T
private static final BigInteger JOINT_ISO_ITU_T
-
-
Constructor Detail
-
Oid
private Oid(String oidString, byte[] oidBytes)
Creates a new instance of Oid.- Parameters:
oidString- The OID as a StringoidBytes- The OID as a byte[]
-
-
Method Detail
-
fromBytes
public static Oid fromBytes(byte[] oidBytes) throws DecoderException
Decodes an OID from abyte[].- Parameters:
oidBytes- The encodedbyte[]- Returns:
- A new Oid
- Throws:
DecoderException- When the OID is not valid
-
processStateStart
private static Oid.OidFSAState processStateStart(String oid, byte[] buffer, int pos) throws DecoderException
Process state A(Start) --['0','1']--> (A) (start) --['2']--> (F)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateA
private static Oid.OidFSAState processStateA(String oid, int pos) throws DecoderException
Process state B(A) --['.']--> (B)
- Parameters:
oid- The OID to checkpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateB
private static Oid.OidFSAState processStateB(String oid, byte[] buffer, int pos) throws DecoderException
Process state B(B) --['0']--> (D) (B) --['1'..'3']--> (C) (B) --['4'..'9']--> (E)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateC
private static Oid.OidFSAState processStateC(String oid, byte[] buffer, int pos) throws DecoderException
Process state C(C) --['.']--> (K) (C) --['0'..'9']--> (E)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateDE
private static Oid.OidFSAState processStateDE(String oid, byte[] buffer, int pos) throws DecoderException
Process state D and E(D) --['.']--> (K) (E) --['.']--> (K)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateF
private static Oid.OidFSAState processStateF(String oid, int pos) throws DecoderException
Process state F(F) --['.']--> (G)
- Parameters:
oid- The OID to checkpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateG
private static Oid.OidFSAState processStateG(String oid, byte[] buffer, int pos) throws DecoderException
Process state G(G) --['0']--> (I) (G) --['1'..'9']--> (H)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateH
private static Oid.OidFSAState processStateH(String oid, byte[] buffer, int pos) throws DecoderException
Process state H(H) --['.']--> (K) (H) --['0'..'9']--> (J)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateI
private static Oid.OidFSAState processStateI(String oid, byte[] buffer, int pos) throws DecoderException
Process state I(I) --['.']--> (K)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateJ
private static Oid.OidFSAState processStateJ(String oid, byte[] buffer, int bufferPos, int pos) throws DecoderException
Process state J(J) --['.']--> (K) (J) --['0'..'9']--> (J)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDbufferPos- The current position in the bufferpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateK
private static Oid.OidFSAState processStateK(String oid, byte[] buffer, int bufferPos, int pos) throws DecoderException
Process state J(K) --['0']--> (M) (K) --['1'..'9']--> (L)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDbufferPos- The current position in the bufferpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateL
private static Oid.OidFSAState processStateL(String oid, byte[] buffer, int bufferPos, int pos) throws DecoderException
Process state J(L) --['.']--> (K) (L) --['0'..'9']--> (L)
- Parameters:
oid- The OID to checkbuffer- The buffer gathering the binary OIDbufferPos- The current position in the bufferpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
processStateM
private static Oid.OidFSAState processStateM(String oid, int pos) throws DecoderException
Process state J(M) --['.']--> (K)
- Parameters:
oid- The OID to checkpos- The position in the OID string- Returns:
- The next OID decoding state
- Throws:
DecoderException- If the OID is invalid
-
convert
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. We must start by the end, and we don't know how many bytes we will need, except when we will be done with the conversion.- Parameters:
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 OID- Returns:
- The number of bytes required to store the OID in a PDU
-
fromString
public static Oid fromString(String oidString) throws DecoderException
Returns an OID object representingoidString.- Parameters:
oidString- The string representation of the OID- Returns:
- A new Oid
- Throws:
DecoderException- When the OID is not valid
-
getEncodedLength
public int getEncodedLength()
Returns the length of the encodedbyte[]representation.- Returns:
- The length of the byte[]
-
isOid
public static boolean isOid(String oidString)
Returns true ifoidStringis a valid string representation of an OID. This method simply callsfromString(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 callingfromString(String).- Parameters:
oidString- The string to test- Returns:
- True, if
oidStringis valid
-
toBytes
public byte[] toBytes()
Returns thebyte[]representation of the OID. Thebyte[]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, thewriteBytesTo(OutputStream)should be used instead as it will avoid creating this copy.- Returns:
- The encoded
byte[]representation of the OID.
-
toString
public String toString()
Returns the string representation of the OID.
-
writeBytesTo
public void writeBytesTo(ByteBuffer buffer)
Writes the bytes respresenting this OID to the provided buffer. This should be used in preference to thetoBytes()method in order to prevent the creation of copies of the actualbyte[].- Parameters:
buffer- The buffer to write the bytes into
-
writeBytesTo
public void writeBytesTo(OutputStream outputStream) throws IOException
Writes the bytes respresenting this OID to the provided stream. This should be used in preference to thetoBytes()method in order to prevent the creation of copies of the actualbyte[].- Parameters:
outputStream- The stream to write the bytes to- Throws:
IOException- When we can't write the OID into a Stream
-
-