Documentation ¶
Overview ¶
Package tpmutil provides common utility functions for both TPM 1.2 and TPM 2.0 devices.
Index ¶
- func OpenTPM(path string) (io.ReadWriteCloser, error)
- func Pack(elts ...interface{}) ([]byte, error)
- func Unpack(b []byte, elts ...interface{}) (int, error)
- func UnpackBuf(buf io.Reader, elts ...interface{}) error
- type Command
- type EmulatorReadWriteCloser
- type Handle
- type RawBytes
- type ResponseCode
- type SelfMarshaler
- type Tag
- type U16Bytes
- type U32Bytes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenTPM ¶
func OpenTPM(path string) (io.ReadWriteCloser, error)
OpenTPM opens a channel to the TPM at the given path. If the file is a device, then it treats it like a normal TPM device, and if the file is a Unix domain socket, then it opens a connection to the socket.
func Pack ¶
Pack encodes a set of elements into a single byte array, using encoding/binary. This means that all the elements must be encodeable according to the rules of encoding/binary.
It has one difference from encoding/binary: it encodes byte slices with a prepended length, to match how the TPM encodes variable-length arrays. If you wish to add a byte slice without length prefix, use RawBytes.
func Unpack ¶
Unpack is a convenience wrapper around UnpackBuf. Unpack returns the number of bytes read from b to fill elts and error, if any.
func UnpackBuf ¶
UnpackBuf recursively unpacks types from a reader just as encoding/binary does under binary.BigEndian, but with one difference: it unpacks a byte slice by first reading an integer with lengthPrefixSize bytes, then reading that many bytes. It assumes that incoming values are pointers to values so that, e.g., underlying slices can be resized as needed.
Types ¶
type EmulatorReadWriteCloser ¶
type EmulatorReadWriteCloser struct {
// contains filtered or unexported fields
}
EmulatorReadWriteCloser manages connections with a TPM emulator over a Unix domain socket. These emulators often operate in a write/read/disconnect sequence, so the Write method always connects, and the Read method always closes. EmulatorReadWriteCloser is not thread safe.
func NewEmulatorReadWriteCloser ¶
func NewEmulatorReadWriteCloser(path string) *EmulatorReadWriteCloser
NewEmulatorReadWriteCloser stores information about a Unix domain socket to write to and read from.
func (*EmulatorReadWriteCloser) Close ¶
func (erw *EmulatorReadWriteCloser) Close() error
Close implements io.Closer by closing the Unix domain socket if one is open.
type RawBytes ¶
type RawBytes []byte
RawBytes is for Pack and RunCommand arguments that are already encoded. Compared to []byte, RawBytes will not be prepended with slice length during encoding.
type ResponseCode ¶
type ResponseCode uint32
ResponseCode is a response code returned by TPM.
const RCRetry ResponseCode = 0x922
RCRetry is response code for TPM is busy.
const RCSuccess ResponseCode = 0x000
RCSuccess is response code for successful command. Identical for TPM 1.2 and 2.0.
func RunCommand ¶
func RunCommand(rw io.ReadWriter, tag Tag, cmd Command, in ...interface{}) ([]byte, ResponseCode, error)
RunCommand executes cmd with given tag and arguments. Returns TPM response body (without response header) and response code from the header. Returned error may be nil if response code is not RCSuccess; caller should check both.
type SelfMarshaler ¶
SelfMarshaler allows custom types to override default encoding/decoding behavior in Pack, Unpack and UnpackBuf.
type U16Bytes ¶
type U16Bytes []byte
U16Bytes is a byte slice with a 16-bit header
func (*U16Bytes) TPMMarshal ¶
TPMMarshal packs U16Bytes
type U32Bytes ¶
type U32Bytes []byte
U32Bytes is a byte slice with a 32-bit header
func (*U32Bytes) TPMMarshal ¶
TPMMarshal packs U32Bytes