Package tss
Class TpmBuffer
- java.lang.Object
-
- tss.TpmBuffer
-
public class TpmBuffer extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
TpmBuffer.SizedStructInfo
Information about the TPM data structure being currently unmarshaled.
-
Constructor Summary
Constructors Constructor Description TpmBuffer()
Constructs output marshling buffer with the default capacity of 4096 bytesTpmBuffer(byte[] buf)
Constructs an initialized input marshling bufferTpmBuffer(int capacity)
Constructs an output marshling buffer with the given capacity
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
buffer()
void
clear()
<T extends TpmMarshaller>
TcreateObj(Class<T> type)
<T extends TpmMarshaller>
TcreateSizedObj(Class<T> type)
int
curPos()
void
curPos(int newPos)
Sets current read/write position in the the backing byte bufferint
getCurStuctRemainingSize()
boolean
isOk()
byte
readByte()
Reads a byte from this buffer.byte[]
readByteBuf(int size)
Unmarshalls a byte buffer of the given size (no marshaled length prefix).int
readInt()
Unmarshals a 32-bit integer from this buffer.long
readInt64()
Unmarshals a 64-bit integer from this buffer.long
readNum(int len)
<T extends TpmMarshaller>
T[]readObjArr(Class<T> type)
int
readShort()
Unmarshals a 16-bit integer from this buffer.byte[]
readSizedByteBuf()
byte[]
readSizedByteBuf(int sizeLen)
Unmarshals a byte buffer from its size-prefixed representation in the TPM wire format.void
reset()
int
size()
byte[]
trim()
Shrinks the backing byte buffer so that it ends at the current positionvoid
writeByte(byte val)
Writes the given 8-bit integer to this buffer<T extends TpmEnum<T>>
voidwriteByte(TpmEnum<T> val)
void
writeByteBuf(byte[] data)
Marshalls the given byte buffer with no length prefix.void
writeInt(int val)
Marshals the given 32-bit integer to this buffer.<T extends TpmEnum<T>>
voidwriteInt(TpmEnum<T> val)
void
writeInt64(long val)
Marshals the given 64-bit integer to this buffer.void
writeNum(long val, int len)
void
writeNumAtPos(int val, int pos)
void
writeNumAtPos(int val, int pos, int len)
void
writeObjArr(TpmMarshaller[] arr)
void
writeShort(int val)
Marshals the given 16-bit integer to this buffer.<T extends TpmEnum<T>>
voidwriteShort(TpmEnum<T> val)
void
writeSizedByteBuf(byte[] data)
void
writeSizedByteBuf(byte[] data, int sizeLen)
Marshalls the given byte buffer with a length prefix.<T extends TpmMarshaller>
voidwriteSizedObj(T obj)
-
-
-
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
-
writeShort
public void writeShort(int val)
Marshals the given 16-bit integer to this buffer.- Parameters:
val
- 16-bit integer value to marshal
-
writeInt
public void writeInt(int val)
Marshals the given 32-bit integer to this buffer.- Parameters:
val
- 32-bit integer value to marshal
-
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 marshalsizeLen
- 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()
-
createObj
public <T extends TpmMarshaller> T createObj(Class<T> type)
-
writeSizedObj
public <T extends TpmMarshaller> void writeSizedObj(T obj)
-
createSizedObj
public <T extends TpmMarshaller> T createSizedObj(Class<T> type)
-
writeObjArr
public void writeObjArr(TpmMarshaller[] arr)
-
readObjArr
public <T extends TpmMarshaller> T[] readObjArr(Class<T> type)
-
-