-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
43 lines (35 loc) · 1.02 KB
/
error.go
File metadata and controls
43 lines (35 loc) · 1.02 KB
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
/*
* Copyright (C) 2020 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
package tpmprovider
import (
"fmt"
)
var errorMessageMap = map[int]string{
TPM_PROVIDER_ERROR_NO_EK_CERT: "The TPM does not have an EK Certificate",
TPM_PROVIDER_EK_PUBLIC_MISMATCH: "EK generation failed: The EK does not have a public key that matches the EK Certificate's",
TPM_PROVIDER_INVALID_PCRSELECTION: "Invalid PCR Selection parameters supplied",
TPM_PROVIDER_INVALID_PCRCOUNT: "Invalid number of banks in response",
}
// TpmProviderError maps error messages to error codes returned from the tpm-provider's
// cgo functions.
type TpmProviderError struct {
ErrorCode int
Message string
}
func (e *TpmProviderError) Error() string {
return fmt.Sprintf("%s", e.Message)
}
func NewTpmProviderError(errorCode int) *TpmProviderError {
var message string
if lookup, ok := errorMessageMap[errorCode]; ok {
message = lookup
} else {
message = ""
}
return &TpmProviderError{
ErrorCode: errorCode,
Message: message,
}
}