Package org.ldaptive.asn1
Class OidType
java.lang.Object
org.ldaptive.asn1.AbstractDERType
org.ldaptive.asn1.OidType
- All Implemented Interfaces:
DEREncoder
Converts object identifiers to and from their DER encoded format.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringConverts bytes in the buffer to an OID by reading from the current position to the limit, which assumes the bytes of the integer are in big-endian order.byte[]encode()Encode this object into its DER type.protected static voidisValid(int[] oid) Checks whether the supplied oid is valid.static int[]Converts the supplied oid into an array on integers.protected static intReads the necessary encoded bytes from the supplied buffer to create an integer.protected static byte[]toBytes(int component) Converts the supplied oid component to a byte array.static byte[]toBytes(int[] oid) Converts the supplied list of oid components to a byte array.Methods inherited from class org.ldaptive.asn1.AbstractDERType
encode
-
Field Details
-
derItem
private final byte[] derItemInteger to encode.
-
-
Constructor Details
-
OidType
Creates a new oid type.- Parameters:
item- to DER encode
-
OidType
public OidType(int[] item) Creates a new oid type.- Parameters:
item- to DER encode
-
OidType
Creates a new oid type.- Parameters:
tag- der tag associated with this typeitem- to DER encode- Throws:
IllegalArgumentException- if the der tag is constructed
-
OidType
Creates a new oid type.- Parameters:
tag- der tag associated with this typeitem- to DER encode- Throws:
IllegalArgumentException- if the der tag is constructed
-
-
Method Details
-
encode
public byte[] encode()Description copied from interface:DEREncoderEncode this object into its DER type.- Specified by:
encodein interfaceDEREncoder- Returns:
- DER encoded object
-
decode
Converts bytes in the buffer to an OID by reading from the current position to the limit, which assumes the bytes of the integer are in big-endian order.- Parameters:
encoded- buffer containing DER-encoded data where the buffer is positioned at the start of OID bytes and the limit is set beyond the last byte of OID data.- Returns:
- decoded bytes as an OID.
-
toBytes
public static byte[] toBytes(int[] oid) Converts the supplied list of oid components to a byte array.- Parameters:
oid- to convert- Returns:
- byte array
- Throws:
IllegalArgumentException- if the oid is not valid. SeeisValid(int[])
-
isValid
protected static void isValid(int[] oid) Checks whether the supplied oid is valid. Oids must meet the following criteria:- must not be null and must have at least 2 elements
- components must not be negative
- first component must be 0, 1, or 2
- if first component 0 or 1, second component must be <= 38
- Parameters:
oid- to check- Throws:
IllegalArgumentException- if the oid is not valid.
-
toBytes
protected static byte[] toBytes(int component) Converts the supplied oid component to a byte array. The length of the byte array is the minimal size needed to contain the oid component.- Parameters:
component- to convert to bytes- Returns:
- oid bytes
-
readInt
Reads the necessary encoded bytes from the supplied buffer to create an integer.- Parameters:
buffer- to read- Returns:
- OID component integer
-
parse
Converts the supplied oid into an array on integers.- Parameters:
oid- to parse- Returns:
- array of oid components
- Throws:
IllegalArgumentException- if the oid is not valid. SeeisValid(int[])
-