Package org.ldaptive.asn1
Class OidType
- java.lang.Object
-
- org.ldaptive.asn1.AbstractDERType
-
- org.ldaptive.asn1.OidType
-
- All Implemented Interfaces:
DEREncoder
public class OidType extends AbstractDERType implements DEREncoder
Converts object identifiers to and from their DER encoded format.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
derItem
Integer to encode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
decode(DERBuffer encoded)
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.byte[]
encode()
Encode this object into its DER type.protected static void
isValid(int[] oid)
Checks whether the supplied oid is valid.static int[]
parse(String oid)
Converts the supplied oid into an array on integers.protected static int
readInt(DERBuffer buffer)
Reads 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
-
-
-
-
Constructor Detail
-
OidType
public OidType(String item)
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
public OidType(DERTag tag, String item)
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
public OidType(DERTag tag, int[] item)
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 Detail
-
encode
public byte[] encode()
Description copied from interface:DEREncoder
Encode this object into its DER type.- Specified by:
encode
in interfaceDEREncoder
- Returns:
- DER encoded object
-
decode
public static String decode(DERBuffer encoded)
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
protected static int readInt(DERBuffer buffer)
Reads the necessary encoded bytes from the supplied buffer to create an integer.- Parameters:
buffer
- to read- Returns:
- OID component integer
-
parse
public static int[] parse(String oid)
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[])
-
-