// NewTPMContext initialises a new TPM context and sets up the // internal TSS structures. func NewTPMContext() (*TPMContext, error) { var result C.TSS_RESULT var ctx TPMContext C.Tspi_Context_Create(&ctx.ctx) result = C.Tspi_Context_Connect(ctx.ctx, nil) if result != C.TSS_SUCCESS { switch result { case C.TSS_E_INVALID_HANDLE: return nil, ErrInvalidHandle case C.TSS_E_INTERNAL_ERROR: return nil, ErrInternalError default: return nil, ErrUnknown } } result = C.Tspi_Context_GetTpmObject(ctx.ctx, &ctx.tpm) if result != C.TSS_SUCCESS { switch result { case C.TSS_E_INVALID_HANDLE: return nil, ErrInvalidHandle case C.TSS_E_INTERNAL_ERROR: return nil, ErrInternalError case C.TSS_E_BAD_PARAMETER: return nil, ErrBadParameter default: return nil, ErrUnknown } } return &ctx, nil }
func NewContext() (*Context, error) { c := new(Context) if result := C.Tspi_Context_Create(&c.ctx); isError(result) { return nil, Error{result} } if result := C.Tspi_Context_Connect(c.ctx, nil /* local TPM */); isError(result) { return nil, Error{result} } if result := C.Tspi_Context_GetTpmObject(c.ctx, &c.tpm); isError(result) { return nil, Error{result} } return c, nil }
// NewContext returns a TSS daemon context func NewContext() (*Context, error) { context := new(Context) err := tspiError(C.Tspi_Context_Create(&context.context)) return context, err }