func (nv *NVRAM) Write(contents []byte) error { if result := C.Tspi_SetAttribUint32(nv.handle, C.TSS_TSPATTRIB_NV_INDEX, 0, C.UINT32(nv.Index)); isError(result) { return Error{result} } if result := C.Tspi_NV_WriteValue(C.TSS_HNVSTORE(nv.handle), 0 /* offset */, C.UINT32(len(contents)), (*C.BYTE)(&contents[0])); isError(result) { return Error{result} } return nil }
func (nv *NVRAM) Destroy() error { if err := nv.setAttributes(); err != nil { return err } if result := C.Tspi_NV_ReleaseSpace(C.TSS_HNVSTORE(nv.handle)); isError(result) { return Error{result} } return nil }
func (nv *NVRAM) Create() error { if err := nv.setAttributes(); err != nil { return err } if result := C.Tspi_NV_DefineSpace(C.TSS_HNVSTORE(nv.handle), 0, 0); isError(result) { return Error{result} } return nil }
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 }