Implement fmt.Stringer on HashAlg (#109)

This commit is contained in:
Tom D 2019-09-23 12:37:40 -07:00 committed by GitHub
parent b60a7ccac1
commit cf79e026c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -301,6 +301,17 @@ func (a HashAlg) goTPMAlg() tpm2.Algorithm {
return 0
}
// String returns a human-friendly representation of the hash algorithm.
func (a HashAlg) String() string {
switch a {
case HashSHA1:
return "SHA1"
case HashSHA256:
return "SHA256"
}
return fmt.Sprintf("HashAlg<%d>", int(a))
}
var (
defaultOpenConfig = &OpenConfig{}

View File

@ -63,7 +63,7 @@ func (k *key12) activateCredential(t *platformTPM, in EncryptedCredential) ([]by
func (k *key12) quote(t *platformTPM, nonce []byte, alg HashAlg) (*Quote, error) {
if alg != HashSHA1 {
return nil, fmt.Errorf("only SHA1 algorithms supported on TPM 1.2, not HashAlg(%v)", alg)
return nil, fmt.Errorf("only SHA1 algorithms supported on TPM 1.2, not %v", alg)
}
quote, rawSig, err := attestation.GetQuote(t.ctx, k.blob, nonce)

View File

@ -57,7 +57,7 @@ func (k *key12) activateCredential(tpm *platformTPM, in EncryptedCredential) ([]
func (k *key12) quote(t *platformTPM, nonce []byte, alg HashAlg) (*Quote, error) {
if alg != HashSHA1 {
return nil, fmt.Errorf("only SHA1 algorithms supported on TPM 1.2, not HashAlg(%v)", alg)
return nil, fmt.Errorf("only SHA1 algorithms supported on TPM 1.2, not %v", alg)
}
tpmKeyHnd, err := t.pcp.TPMKeyHandle(k.hnd)