Class OidType

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] derItem
      Integer to encode.
    • Constructor Summary

      Constructors 
      Constructor Description
      OidType​(int[] item)
      Creates a new oid type.
      OidType​(String item)
      Creates a new oid type.
      OidType​(DERTag tag, int[] item)
      Creates a new oid type.
      OidType​(DERTag tag, String item)
      Creates a new oid type.
    • Field Detail

      • derItem

        private final byte[] derItem
        Integer to 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 type
        item - 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 type
        item - 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 interface DEREncoder
        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. 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:
        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. See isValid(int[])