func (nv *NVRAM) Read(out []byte) (int, error) { if result := C.Tspi_SetAttribUint32(nv.handle, C.TSS_TSPATTRIB_NV_INDEX, 0, C.UINT32(nv.Index)); isError(result) { return 0, Error{result} } l32 := C.UINT32(len(out)) var buf *C.BYTE if result := C.Tspi_NV_ReadValue(C.TSS_HNVSTORE(nv.handle), 0 /* offset */, &l32, &buf); isError(result) { return 0, Error{result} } l := int(l32) if l > len(out) { l = len(out) } if l < 0 { l = 0 } C.memcpy(unsafe.Pointer(&out[0]), unsafe.Pointer(buf), C.size_t(l)) return l, nil }
// ReadValue reads length bytes from offset in the TPM NVRAM space func (nv *NV) ReadValue(offset uint, length uint) ([]byte, error) { data := make([]byte, length) err := tspiError(C.Tspi_NV_ReadValue(nv.handle, (C.UINT32)(offset), (*C.UINT32)(unsafe.Pointer(&length)), (**C.BYTE)(unsafe.Pointer(&data)))) return data, err }