Package org.conscrypt.ct
Class Serialization
- java.lang.Object
-
- org.conscrypt.ct.Serialization
-
@Internal public class Serialization extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static int
DER_LENGTH_LONG_FORM_FLAG
private static int
DER_TAG_MASK
private static int
DER_TAG_OCTET_STRING
-
Constructor Summary
Constructors Modifier Constructor Description private
Serialization()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte
readByte(java.io.InputStream input)
Read a single byte from the input stream.static byte[]
readDEROctetString(byte[] input)
static byte[]
readDEROctetString(java.io.InputStream input)
static byte[]
readFixedBytes(java.io.InputStream input, int length)
Read a fixed number of bytes from the input stream.static byte[][]
readList(byte[] input, int listWidth, int elemWidth)
static byte[][]
readList(java.io.InputStream input, int listWidth, int elemWidth)
Read a variable length vector of variable sized elements as described by RFC5246 section 4.3.static long
readLong(java.io.InputStream input, int width)
Read a number in big endian format from the input stream.static int
readNumber(java.io.InputStream input, int width)
Read a number in big endian format from the input stream.static byte[]
readVariableBytes(java.io.InputStream input, int width)
Read a length-prefixed sequence of bytes.static void
writeFixedBytes(java.io.OutputStream output, byte[] data)
Write a fixed number sequence of bytes to the ouput stream.static void
writeNumber(java.io.OutputStream output, long value, int width)
Write a number to the output stream.static void
writeVariableBytes(java.io.OutputStream output, byte[] data, int width)
Write length prefixed sequence of bytes to the ouput stream.
-
-
-
Field Detail
-
DER_TAG_MASK
private static final int DER_TAG_MASK
- See Also:
- Constant Field Values
-
DER_TAG_OCTET_STRING
private static final int DER_TAG_OCTET_STRING
- See Also:
- Constant Field Values
-
DER_LENGTH_LONG_FORM_FLAG
private static final int DER_LENGTH_LONG_FORM_FLAG
- See Also:
- Constant Field Values
-
-
Method Detail
-
readDEROctetString
public static byte[] readDEROctetString(byte[] input) throws SerializationException
- Throws:
SerializationException
-
readDEROctetString
public static byte[] readDEROctetString(java.io.InputStream input) throws SerializationException
- Throws:
SerializationException
-
readList
public static byte[][] readList(byte[] input, int listWidth, int elemWidth) throws SerializationException
- Throws:
SerializationException
-
readList
public static byte[][] readList(java.io.InputStream input, int listWidth, int elemWidth) throws SerializationException
Read a variable length vector of variable sized elements as described by RFC5246 section 4.3. The vector is prefixed by its total length, in bytes and in big endian format, so is each element contained in the vector.- Parameters:
listWidth
- the width of the vector's length field, in bytes.elemWidth
- the width of each element's length field, in bytes.- Throws:
SerializationException
- if EOF is encountered.
-
readVariableBytes
public static byte[] readVariableBytes(java.io.InputStream input, int width) throws SerializationException
Read a length-prefixed sequence of bytes. The length must be encoded in big endian format.- Parameters:
width
- the width of the length prefix, in bytes.- Throws:
SerializationException
- if EOF is encountered, or ifwidth
is negative or greater than 4
-
readFixedBytes
public static byte[] readFixedBytes(java.io.InputStream input, int length) throws SerializationException
Read a fixed number of bytes from the input stream.- Parameters:
length
- the number of bytes to read.- Throws:
SerializationException
- if EOF is encountered.
-
readNumber
public static int readNumber(java.io.InputStream input, int width) throws SerializationException
Read a number in big endian format from the input stream. This methods only supports a width of up to 4 bytes.- Parameters:
width
- the width of the number, in bytes.- Throws:
SerializationException
- if EOF is encountered, or ifwidth
is negative or greater than 4
-
readLong
public static long readLong(java.io.InputStream input, int width) throws SerializationException
Read a number in big endian format from the input stream. This methods supports a width of up to 8 bytes.- Parameters:
width
- the width of the number, in bytes.- Throws:
SerializationException
- if EOF is encountered.java.lang.IllegalArgumentException
- ifwidth
is negative or greater than 8
-
readByte
public static byte readByte(java.io.InputStream input) throws SerializationException
Read a single byte from the input stream.- Throws:
SerializationException
- if EOF is encountered.
-
writeVariableBytes
public static void writeVariableBytes(java.io.OutputStream output, byte[] data, int width) throws SerializationException
Write length prefixed sequence of bytes to the ouput stream. The length prefix is encoded in big endian order.- Parameters:
data
- the data to be written.width
- the width of the length prefix, in bytes.- Throws:
SerializationException
- if the length ofdata
is too large to fit inwidth
bytes orwidth
is negative.
-
writeFixedBytes
public static void writeFixedBytes(java.io.OutputStream output, byte[] data) throws SerializationException
Write a fixed number sequence of bytes to the ouput stream.- Parameters:
data
- the data to be written.- Throws:
SerializationException
-
writeNumber
public static void writeNumber(java.io.OutputStream output, long value, int width) throws SerializationException
Write a number to the output stream. The number is encoded in big endian order.- Parameters:
value
- the value to be written.width
- the width of the encoded number, in bytes- Throws:
SerializationException
- if the number is too large to fit inwidth
bytes orwidth
is negative.
-
-