-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_tpmprovider.go
149 lines (119 loc) · 4.89 KB
/
mock_tpmprovider.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// +build unit_test
/*
* Copyright (C) 2020 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
package tpmprovider
// #include "tpm.h"
import "C"
import (
"github.com/stretchr/testify/mock"
)
type MockedTpmFactory struct {
TpmProvider *MockedTpmProvider
}
func (mockedTpmFactory MockedTpmFactory) NewTpmProvider() (TpmProvider, error) {
return mockedTpmFactory.TpmProvider, nil
}
//-------------------------------------------------------------------------------------------------
// Mocked TpmProvider interface
//-------------------------------------------------------------------------------------------------
type MockedTpmProvider struct {
mock.Mock
}
func (mockedTpm MockedTpmProvider) Close() {
_ = mockedTpm.Called()
return
}
func (mockedTpm MockedTpmProvider) Version() C.TPM_VERSION {
args := mockedTpm.Called()
return args.Get(0).(C.TPM_VERSION)
}
func (mockedTpm MockedTpmProvider) TakeOwnership(ownerSecretKey string) error {
args := mockedTpm.Called(ownerSecretKey)
return args.Error(0)
}
func (mockedTpm MockedTpmProvider) IsOwnedWithAuth(ownerSecretKey string) (bool, error) {
args := mockedTpm.Called(ownerSecretKey)
return args.Bool(0), args.Error(1)
}
func (mockedTpm MockedTpmProvider) CreateAik(ownerSecretKey string) error {
args := mockedTpm.Called(ownerSecretKey)
return args.Error(0)
}
func (mockedTpm MockedTpmProvider) GetAikBytes() ([]byte, error) {
args := mockedTpm.Called()
return args.Get(0).([]byte), args.Error(1)
}
func (mockedTpm MockedTpmProvider) GetAikName() ([]byte, error) {
args := mockedTpm.Called()
return args.Get(0).([]byte), args.Error(1)
}
func (mockedTpm MockedTpmProvider) ActivateCredential(ownerSecretKey string, credentialBytes []byte, secretBytes []byte) ([]byte, error) {
args := mockedTpm.Called(ownerSecretKey, credentialBytes, secretBytes)
return args.Get(0).([]byte), args.Error(1)
}
func (mockedTpm MockedTpmProvider) GetTpmQuote(nonce []byte, pcrBanks []string, pcrs []int) ([]byte, error) {
args := mockedTpm.Called(nonce, pcrBanks, pcrs)
return args.Get(0).([]byte), args.Error(1)
}
func (mockedTpm MockedTpmProvider) NvIndexExists(nvIndex uint32) (bool, error) {
args := mockedTpm.Called(nvIndex)
return args.Bool(0), args.Error(1)
}
func (mockedTpm MockedTpmProvider) NvDefine(ownerSecretKey string, indexSecretKey string, nvIndex uint32, indexSize uint16) error {
args := mockedTpm.Called(ownerSecretKey, indexSecretKey, nvIndex, indexSize)
return args.Error(0)
}
func (mockedTpm MockedTpmProvider) NvRelease(ownerSecretKey string, nvIndex uint32) error {
args := mockedTpm.Called(ownerSecretKey, nvIndex)
return args.Error(0)
}
func (mockedTpm MockedTpmProvider) NvRead(indexSecretKey string, authHandle uint32, nvIndex uint32) ([]byte, error) {
args := mockedTpm.Called(indexSecretKey, authHandle, nvIndex)
return args.Get(0).([]byte), args.Error(1)
}
func (mockedTpm MockedTpmProvider) NvWrite(indexSecretKey string, authHandle uint32, nvIndex uint32, data []byte) error {
args := mockedTpm.Called(indexSecretKey, authHandle, nvIndex, data)
return args.Error(0)
}
func (mockedTpm MockedTpmProvider) CreatePrimaryHandle(ownerSecretKey string, handle uint32) error {
args := mockedTpm.Called(ownerSecretKey, handle)
return args.Error(0)
}
func (mockedTpm MockedTpmProvider) CreateSigningKey(signingSecretKey string) (*CertifiedKey, error) {
args := mockedTpm.Called(signingSecretKey)
return args.Get(0).(*CertifiedKey), args.Error(1)
}
func (mockedTpm MockedTpmProvider) CreateBindingKey(bindingSecretKey string) (*CertifiedKey, error) {
args := mockedTpm.Called(bindingSecretKey)
return args.Get(0).(*CertifiedKey), args.Error(1)
}
func (mockedTpm MockedTpmProvider) Unbind(certifiedKey *CertifiedKey, ownerSecretKey string, encryptedData []byte) ([]byte, error) {
args := mockedTpm.Called(certifiedKey, ownerSecretKey, encryptedData)
return args.Get(0).([]byte), args.Error(1)
}
func (mockedTpm MockedTpmProvider) Sign(certifiedKey *CertifiedKey, ownerSecretKey string, hash []byte) ([]byte, error) {
args := mockedTpm.Called(certifiedKey, ownerSecretKey, hash)
return args.Get(0).([]byte), args.Error(1)
}
func (mockedTpm MockedTpmProvider) PublicKeyExists(handle uint32) (bool, error) {
args := mockedTpm.Called(handle)
return args.Bool(0), args.Error(1)
}
func (mockedTpm MockedTpmProvider) ReadPublic(handle uint32) ([]byte, error) {
args := mockedTpm.Called(handle)
return args.Get(0).([]byte), args.Error(1)
}
func (mockedTpm MockedTpmProvider) CreateEk(ownerSecretKey string, handle uint32) error {
args := mockedTpm.Called(ownerSecretKey, handle)
return args.Error(0)
}
func (mockedTpm MockedTpmProvider) IsValidEk(ownerSecretKey string, handle uint32, nvIndex uint32) (bool, error) {
args := mockedTpm.Called(ownerSecretKey, handle, nvIndex)
return args.Bool(0), args.Error(1)
}
func (mockedTpm MockedTpmProvider) IsPcrBankActive(pcrBank string) (bool, error) {
args := mockedTpm.Called(pcrBank)
return args.Bool(0), args.Error(1)
}