Skip to content

Commit dd1d2c4

Browse files
Merge pull request #49 from chrisccoulson/switch-to-canonical-go-tpm2
Switch from chrisccoulson/go-tpm2 to canonical/go-tpm2
2 parents db2faf5 + 115ea8d commit dd1d2c4

26 files changed

+52
-46
lines changed

constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package secboot
2121

2222
import (
23-
"github.com/chrisccoulson/go-tpm2"
23+
"github.com/canonical/go-tpm2"
2424
)
2525

2626
const (

crypt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"path/filepath"
2929
"strings"
3030

31-
"github.com/chrisccoulson/go-tpm2"
31+
"github.com/canonical/go-tpm2"
3232
. "github.com/snapcore/secboot"
3333
"github.com/snapcore/snapd/testutil"
3434

errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"errors"
2424
"fmt"
2525

26-
"github.com/chrisccoulson/go-tpm2"
26+
"github.com/canonical/go-tpm2"
2727

2828
"golang.org/x/xerrors"
2929
)

export_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"io"
2525
"os"
2626

27-
"github.com/chrisccoulson/go-tpm2"
27+
"github.com/canonical/go-tpm2"
2828
"github.com/chrisccoulson/tcglog-parser"
2929
)
3030

keydata.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"math/big"
3131
"os"
3232

33-
"github.com/chrisccoulson/go-tpm2"
33+
"github.com/canonical/go-tpm2"
3434
"github.com/snapcore/snapd/osutil"
3535
"github.com/snapcore/snapd/osutil/sys"
3636

@@ -75,7 +75,7 @@ type keyData struct {
7575
func readKeyPolicyUpdateData(buf io.Reader) (*keyPolicyUpdateData, error) {
7676
var header uint32
7777
var version uint32
78-
if err := tpm2.UnmarshalFromReader(buf, &header, &version); err != nil {
78+
if _, err := tpm2.UnmarshalFromReader(buf, &header, &version); err != nil {
7979
return nil, xerrors.Errorf("cannot unmarshal header and version number: %w", err)
8080
}
8181

@@ -87,7 +87,7 @@ func readKeyPolicyUpdateData(buf io.Reader) (*keyPolicyUpdateData, error) {
8787
}
8888

8989
var d keyPolicyUpdateData
90-
if err := tpm2.UnmarshalFromReader(buf, &d); err != nil {
90+
if _, err := tpm2.UnmarshalFromReader(buf, &d); err != nil {
9191
return nil, xerrors.Errorf("cannot unmarshal key data: %w", err)
9292
}
9393

@@ -96,7 +96,10 @@ func readKeyPolicyUpdateData(buf io.Reader) (*keyPolicyUpdateData, error) {
9696

9797
// write serializes keyPolicyUpdateData to the provided io.Writer.
9898
func (d *keyPolicyUpdateData) write(buf io.Writer) error {
99-
return tpm2.MarshalToWriter(buf, keyPolicyUpdateDataHeader, currentVersion, d)
99+
if _, err := tpm2.MarshalToWriter(buf, keyPolicyUpdateDataHeader, currentVersion, d); err != nil {
100+
return err
101+
}
102+
return nil
100103
}
101104

102105
type keyFileError struct {
@@ -120,7 +123,7 @@ func isKeyFileError(err error) bool {
120123
func readKeyData(buf io.Reader) (*keyData, error) {
121124
var header uint32
122125
var version uint32
123-
if err := tpm2.UnmarshalFromReader(buf, &header, &version); err != nil {
126+
if _, err := tpm2.UnmarshalFromReader(buf, &header, &version); err != nil {
124127
return nil, keyFileError{xerrors.Errorf("cannot unmarshal header and version number: %w", err)}
125128
}
126129

@@ -132,7 +135,7 @@ func readKeyData(buf io.Reader) (*keyData, error) {
132135
}
133136

134137
var d keyData
135-
if err := tpm2.UnmarshalFromReader(buf, &d); err != nil {
138+
if _, err := tpm2.UnmarshalFromReader(buf, &d); err != nil {
136139
return nil, keyFileError{xerrors.Errorf("cannot unmarshal key data: %w", err)}
137140
}
138141

@@ -167,7 +170,10 @@ func (d *keyData) load(tpm *tpm2.TPMContext, session tpm2.SessionContext) (tpm2.
167170

168171
// write serializes keyData in to the provided io.Writer.
169172
func (d *keyData) write(buf io.Writer) error {
170-
return tpm2.MarshalToWriter(buf, keyDataHeader, currentVersion, d)
173+
if _, err := tpm2.MarshalToWriter(buf, keyDataHeader, currentVersion, d); err != nil {
174+
return err
175+
}
176+
return nil
171177
}
172178

173179
// writeToFileAtomic serializes keyData and writes it atomically to the file at the specified path.
@@ -178,7 +184,7 @@ func (d *keyData) writeToFileAtomic(dest string) error {
178184
}
179185
defer f.Cancel()
180186

181-
if err := tpm2.MarshalToWriter(f, keyDataHeader, currentVersion, d); err != nil {
187+
if _, err := tpm2.MarshalToWriter(f, keyDataHeader, currentVersion, d); err != nil {
182188
return xerrors.Errorf("cannot marshal key data to temporary file: %w", err)
183189
}
184190

@@ -306,7 +312,7 @@ func validateKeyData(tpm *tpm2.TPMContext, data *keyData, policyUpdateData *keyP
306312

307313
// Verify that the private data structure is bound to the key data structure.
308314
h := data.KeyPublic.NameAlg.NewHash()
309-
if err := tpm2.MarshalToWriter(h, policyUpdateData.CreationData); err != nil {
315+
if _, err := tpm2.MarshalToWriter(h, policyUpdateData.CreationData); err != nil {
310316
panic(fmt.Sprintf("cannot marshal creation data: %v", err))
311317
}
312318

@@ -319,7 +325,7 @@ func validateKeyData(tpm *tpm2.TPMContext, data *keyData, policyUpdateData *keyP
319325
}
320326

321327
h = crypto.SHA256.New()
322-
if err := tpm2.MarshalToWriter(h, &policyUpdateData.Data); err != nil {
328+
if _, err := tpm2.MarshalToWriter(h, &policyUpdateData.Data); err != nil {
323329
panic(fmt.Sprintf("cannot marshal dynamic authorization policy update data: %v", err))
324330
}
325331

pcr_profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package secboot
2222
import (
2323
"fmt"
2424

25-
"github.com/chrisccoulson/go-tpm2"
25+
"github.com/canonical/go-tpm2"
2626

2727
"golang.org/x/xerrors"
2828
)

pcr_profile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"reflect"
2424
"testing"
2525

26-
"github.com/chrisccoulson/go-tpm2"
26+
"github.com/canonical/go-tpm2"
2727
. "github.com/snapcore/secboot"
2828
)
2929

pin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"encoding/binary"
2626
"os"
2727

28-
"github.com/chrisccoulson/go-tpm2"
28+
"github.com/canonical/go-tpm2"
2929

3030
"golang.org/x/xerrors"
3131
)

pin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"os"
2727
"testing"
2828

29-
"github.com/chrisccoulson/go-tpm2"
29+
"github.com/canonical/go-tpm2"
3030
. "github.com/snapcore/secboot"
3131

3232
. "gopkg.in/check.v1"

policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"fmt"
2929
"sort"
3030

31-
"github.com/chrisccoulson/go-tpm2"
31+
"github.com/canonical/go-tpm2"
3232

3333
"golang.org/x/xerrors"
3434
)

0 commit comments

Comments
 (0)