Package tss

Class TpmBuffer


  • public class TpmBuffer
    extends Object
    • Constructor Detail

      • TpmBuffer

        public TpmBuffer()
        Constructs output marshling buffer with the default capacity of 4096 bytes
      • TpmBuffer

        public TpmBuffer​(int capacity)
        Constructs an output marshling buffer with the given capacity
        Parameters:
        capacity - Capacity in bytes
      • TpmBuffer

        public TpmBuffer​(byte[] buf)
        Constructs an initialized input marshling buffer
        Parameters:
        buf - A marshaled representation to initialize the new input buffer with
    • Method Detail

      • clear

        public void clear()
      • reset

        public void reset()
      • buffer

        public byte[] buffer()
        Returns:
        Reference to the backing byte buffer
      • size

        public int size()
        Returns:
        Size of the backing byte buffer. Note that during marshaling this size normally exceeds the amount of actually stored data until trim() is invoked.
      • curPos

        public int curPos()
        Returns:
        Current read/write position in the the backing byte buffer
      • curPos

        public void curPos​(int newPos)
        Sets current read/write position in the the backing byte buffer
        Parameters:
        newPos - New read/write position
      • isOk

        public boolean isOk()
        Returns:
        true unless a previous read/write operation caused under/overflow correspondingly.
      • trim

        public byte[] trim()
        Shrinks the backing byte buffer so that it ends at the current position
        Returns:
        Reference to the shrunk backing byte array
      • getCurStuctRemainingSize

        public int getCurStuctRemainingSize()
      • writeNum

        public void writeNum​(long val,
                             int len)
      • readNum

        public long readNum​(int len)
      • writeNumAtPos

        public void writeNumAtPos​(int val,
                                  int pos,
                                  int len)
      • writeNumAtPos

        public void writeNumAtPos​(int val,
                                  int pos)
      • writeByte

        public void writeByte​(byte val)
        Writes the given 8-bit integer to this buffer
        Parameters:
        val - 8-bit integer value to marshal
      • writeByte

        public <T extends TpmEnum<T>> void writeByte​(TpmEnum<T> val)
      • writeShort

        public void writeShort​(int val)
        Marshals the given 16-bit integer to this buffer.
        Parameters:
        val - 16-bit integer value to marshal
      • writeShort

        public <T extends TpmEnum<T>> void writeShort​(TpmEnum<T> val)
      • writeInt

        public void writeInt​(int val)
        Marshals the given 32-bit integer to this buffer.
        Parameters:
        val - 32-bit integer value to marshal
      • writeInt

        public <T extends TpmEnum<T>> void writeInt​(TpmEnum<T> val)
      • writeInt64

        public void writeInt64​(long val)
        Marshals the given 64-bit integer to this buffer.
        Parameters:
        val - 64-bit integer value to marshal
      • readByte

        public byte readByte()
        Reads a byte from this buffer.
        Returns:
        The byte read
      • readShort

        public int readShort()
        Unmarshals a 16-bit integer from this buffer.
        Returns:
        Unmarshaled 16-bit integer (as 32-bit int because of Java's abysmal unsigned values handling)
      • readInt

        public int readInt()
        Unmarshals a 32-bit integer from this buffer.
        Returns:
        Unmarshaled 32-bit integer
      • readInt64

        public long readInt64()
        Unmarshals a 64-bit integer from this buffer.
        Returns:
        Unmarshaled 64-bit integer
      • writeByteBuf

        public void writeByteBuf​(byte[] data)
        Marshalls the given byte buffer with no length prefix.
        Parameters:
        data - Byte buffer to marshal
      • readByteBuf

        public byte[] readByteBuf​(int size)
        Unmarshalls a byte buffer of the given size (no marshaled length prefix).
        Parameters:
        size - Size of the byte buffer to unmarshal
        Returns:
        Unmarshaled byte buffer
      • writeSizedByteBuf

        public void writeSizedByteBuf​(byte[] data,
                                      int sizeLen)
        Marshalls the given byte buffer with a length prefix.
        Parameters:
        data - Byte buffer to marshal
        sizeLen - Length of the size prefix in bytes
      • writeSizedByteBuf

        public void writeSizedByteBuf​(byte[] data)
      • readSizedByteBuf

        public byte[] readSizedByteBuf​(int sizeLen)
        Unmarshals a byte buffer from its size-prefixed representation in the TPM wire format.
        Parameters:
        sizeLen - Length of the size prefix in bytes
        Returns:
        Unmarshaled byte buffer
      • readSizedByteBuf

        public byte[] readSizedByteBuf()
      • writeSizedObj

        public <T extends TpmMarshaller> void writeSizedObj​(T obj)