Fix building without cgo

This commit is contained in:
Brandon Weeks 2019-10-08 06:11:40 +00:00
parent 59a5f6851d
commit 355782cbf9
5 changed files with 87 additions and 18 deletions

View File

@ -1,4 +1,4 @@
// +build !cgo
// +build cgo
package attest
@ -33,21 +33,6 @@ const (
tpm20GeneratedMagic = 0xff544347
)
func cryptoHash(h tpm2.Algorithm) (crypto.Hash, error) {
switch h {
case tpm2.AlgSHA1:
return crypto.SHA1, nil
case tpm2.AlgSHA256:
return crypto.SHA256, nil
case tpm2.AlgSHA384:
return crypto.SHA384, nil
case tpm2.AlgSHA512:
return crypto.SHA512, nil
default:
return crypto.Hash(0), fmt.Errorf("unsupported signature digest: %v", h)
}
}
// ActivationParameters encapsulates the inputs for activating an AIK.
type ActivationParameters struct {
// TPMVersion holds the version of the TPM, either 1.2 or 2.0.

22
attest/cryptohash.go Normal file
View File

@ -0,0 +1,22 @@
package attest
import (
"crypto"
"fmt"
"github.com/google/go-tpm/tpm2"
)
func cryptoHash(h tpm2.Algorithm) (crypto.Hash, error) {
switch h {
case tpm2.AlgSHA1:
return crypto.SHA1, nil
case tpm2.AlgSHA256:
return crypto.SHA256, nil
case tpm2.AlgSHA384:
return crypto.SHA384, nil
case tpm2.AlgSHA512:
return crypto.SHA512, nil
default:
return crypto.Hash(0), fmt.Errorf("unsupported signature digest: %v", h)
}
}

View File

@ -12,7 +12,7 @@
// License for the specific language governing permissions and limitations under
// the License.
// +build linux !cgo
// +build linux,cgo
package attest

View File

@ -12,7 +12,7 @@
// License for the specific language governing permissions and limitations under
// the License.
// +build linux !cgo
// +build linux,cgo
package attest

62
attest/tpm_other.go Normal file
View File

@ -0,0 +1,62 @@
// Copyright 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
// +build !linux !windows
package attest
type platformTPM struct {
// interf TPMInterface
}
func probeSystemTPMs() ([]probedTPM, error) {
return nil, nil
}
func openTPM(tpm probedTPM) (*TPM, error) {
return nil, nil
}
func (t *platformTPM) tpmVersion() TPMVersion {
return TPMVersionAgnostic
}
func (t *platformTPM) close() error {
return nil
}
func (t *platformTPM) info() (*TPMInfo, error) {
return nil, nil
}
func (t *platformTPM) loadAIK(opaqueBlob []byte) (*AIK, error) {
return nil, nil
}
func (t *platformTPM) eks() ([]EK, error) {
return nil, nil
}
func (t *platformTPM) newAIK(opts *AIKConfig) (*AIK, error) {
return nil, nil
}
func (t *platformTPM) pcrs(alg HashAlg) ([]PCR, error) {
return nil, nil
}
func (t *platformTPM) measurementLog() ([]byte, error) {
return nil, nil
}