-
Notifications
You must be signed in to change notification settings - Fork 10
/
export_test.go
79 lines (65 loc) · 1.84 KB
/
export_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2019 Canonical Ltd.
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.
package tpm2
import (
"bytes"
"crypto/rand"
"io"
"github.com/canonical/go-tpm2/mu"
)
type CmdContext = cmdContext
type NvIndexContextImpl = nvIndexContext
type RspContext = rspContext
type SessionContextData = sessionContextData
type SessionContextImpl = sessionContext // We already have a SessionContext interface
type SessionParam = sessionParam
type SessionParams = sessionParams
var ComputeBindName = computeBindName
var NewExtraSessionParam = newExtraSessionParam
var NewSessionParamForAuth = newSessionParamForAuth
var NewSessionParams = newSessionParams
var NullResource = nullResource
var PwSession = pwSession
func (c *CommandContext) Cmd() *CmdContext {
return &c.cmd
}
func (c *NvIndexContextImpl) Public() *NVPublic {
return c.Data.NV
}
func (c *ResponseContext) Dispatcher() commandDispatcher {
return c.dispatcher
}
func (c *ResponseContext) Rsp() *RspContext {
return c.rsp
}
func Canonicalize(vals ...interface{}) error {
b := new(bytes.Buffer)
if _, err := mu.MarshalToWriter(b, vals...); err != nil {
return err
}
_, err := mu.UnmarshalFromReader(b, vals...)
return err
}
func MockRandReader(r io.Reader) (restore func()) {
orig := rand.Reader
rand.Reader = r
return func() {
rand.Reader = orig
}
}
func NewMockCommandContext(dispatcher commandDispatcher, cmd *CmdContext) *CommandContext {
c := &CommandContext{dispatcher: dispatcher}
if cmd != nil {
c.cmd = *cmd
}
return c
}
func NewMockResponseContext(dispatcher commandDispatcher, rsp *RspContext) *ResponseContext {
return &ResponseContext{
dispatcher: dispatcher,
rsp: rsp}
}
func NewResourceUnavailableError(handle Handle, err error) *ResourceUnavailableError {
return &ResourceUnavailableError{Handle: handle, err: err}
}