Class Asn1


  • public final class Asn1
    extends Object
    This class contains various static factory methods for creating ASN.1 readers and writers.
    See Also:
    Asn1Reader, Asn1Writer
    • Method Detail

      • getReader

        public static Asn1Reader getReader​(byte[] array)
        Returns an ASN.1 reader whose source is the provided byte array and having an unlimited maximum BER element size.
        Parameters:
        array - The byte array to use.
        Returns:
        The new ASN.1 reader.
      • getReader

        public static Asn1Reader getReader​(byte[] array,
                                           int maxElementSize)
        Returns an ASN.1 reader whose source is the provided byte array and having a user defined maximum BER element size.
        Parameters:
        array - The byte array to use.
        maxElementSize - The maximum BER element size, or 0 to indicate that there is no limit.
        Returns:
        The new ASN.1 reader.
      • getReader

        public static Asn1Reader getReader​(ByteString bytes)
        Returns an ASN.1 reader whose source is the provided byte string and having an unlimited maximum BER element size.
        Parameters:
        bytes - The byte string to use.
        Returns:
        The new ASN.1 reader.
      • getReader

        public static Asn1Reader getReader​(ByteString bytes,
                                           int maxElementSize)
        Returns an ASN.1 reader whose source is the provided byte string and having a user defined maximum BER element size.
        Parameters:
        bytes - The byte string to use.
        maxElementSize - The maximum BER element size, or 0 to indicate that there is no limit.
        Returns:
        The new ASN.1 reader.
      • getReader

        public static Asn1Reader getReader​(ByteStringReader reader)
        Returns an ASN.1 reader whose source is the provided byte string reader and having an unlimited maximum BER element size.
        Parameters:
        reader - The byte string reader to use.
        Returns:
        The new ASN.1 reader.
      • getReader

        public static Asn1Reader getReader​(ByteStringReader reader,
                                           int maxElementSize)
        Returns an ASN.1 reader whose source is the provided byte string reader and having a user defined maximum BER element size.
        Parameters:
        reader - The byte string reader to use.
        maxElementSize - The maximum BER element size, or 0 to indicate that there is no limit.
        Returns:
        The new ASN.1 reader.
      • getReader

        public static Asn1Reader getReader​(InputStream stream)
        Returns an ASN.1 reader whose source is the provided input stream and having an unlimited maximum BER element size.
        Parameters:
        stream - The input stream to use.
        Returns:
        The new ASN.1 reader.
      • getReader

        public static Asn1Reader getReader​(InputStream stream,
                                           int maxElementSize)
        Returns an ASN.1 reader whose source is the provided input stream and having a user defined maximum BER element size.
        Parameters:
        stream - The input stream to use.
        maxElementSize - The maximum BER element size, or 0 to indicate that there is no limit.
        Returns:
        The new ASN.1 reader.
      • getWriter

        public static Asn1Writer getWriter()
        Returns an ASN.1 writer with an initial capacity of 32 bytes.
        Returns:
        The new ASN.1 writer.
      • getWriter

        public static Asn1Writer getWriter​(int initialCapacity)
        Returns an ASN.1 writer with the provided initial capacity.
        Parameters:
        initialCapacity - The initial capacity of the internal byte buffer.
        Returns:
        The new ASN.1 writer.
      • writeAsn1Sequence

        public static ByteString writeAsn1Sequence​(Consumer<Asn1Writer> sequenceWriter)
        Writes an ASN.1 sequence using the provided Consumer and returns the encoded bytes.
        Parameters:
        sequenceWriter - A consumer which is responsible for writing the contents of the sequence to the provided ASN.1 writer. Any IOExceptions thrown by the consumer will be treated as runtime errors.
        Returns:
        The encoded ASN.1 sequence.