Class OidType

  • All Implemented Interfaces:
    DEREncoder

    public class OidType
    extends AbstractDERType
    implements DEREncoder
    Converts object identifiers to and from their DER encoded format.
    Author:
    Middleware Services
    • Constructor Summary

      Constructors 
      Constructor Description
      OidType​(int[] item)
      Creates a new oid type.
      OidType​(java.lang.String item)
      Creates a new oid type.
      OidType​(DERTag tag, int[] item)
      Creates a new oid type.
      OidType​(DERTag tag, java.lang.String item)
      Creates a new oid type.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.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 it's DER type.
      protected static void isValid​(int[] oid)
      Checks whether the supplied oid is valid.
      static int[] parse​(java.lang.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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OidType

        public OidType​(java.lang.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,
                       java.lang.String item)
        Creates a new oid type.
        Parameters:
        tag - der tag associated with this type
        item - to DER encode
        Throws:
        java.lang.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 type
        item - to DER encode
        Throws:
        java.lang.IllegalArgumentException - if the der tag is constructed
    • Method Detail

      • encode

        public byte[] encode()
        Description copied from interface: DEREncoder
        Encode this object into it's DER type.
        Specified by:
        encode in interface DEREncoder
        Returns:
        DER encoded object
      • decode

        public static java.lang.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:
        java.lang.IllegalArgumentException - if the oid is not valid. See isValid(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:
        java.lang.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​(java.lang.String oid)
        Converts the supplied oid into an array on integers.
        Parameters:
        oid - to parse
        Returns:
        array of oid components
        Throws:
        java.lang.IllegalArgumentException - if the oid is not valid. See isValid(int[])