mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-12 17:47:02 +02:00
We have many hand-written String() methods (and similar) for enums. These require more maintenance and are more error-prone than using automatically generated methods. In addition, the auto-generated versions can be more efficient. Here, we switch to using https://github.com/loggerhead/enumer, itself a fork of https://github.com/diegostamigni/enumer, no longer maintained, and a fork of the mostly standard tool https://pkg.go.dev/golang.org/x/tools/cmd/stringer. We use this fork of enumer for Go 1.20+ compatibility and because we require the `-transform` flag to be able to generate constants that match our current code base. Some enums were not targeted for this change:
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
// Code generated by "enumer -type=KeyUsage -trimprefix=KeyUsage -transform=snake"; DO NOT EDIT.
|
|
|
|
package logical
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
const _KeyUsageName = "encryptdecryptsignverifywrapunwrapgenerate_random"
|
|
|
|
var _KeyUsageIndex = [...]uint8{0, 7, 14, 18, 24, 28, 34, 49}
|
|
|
|
func (i KeyUsage) String() string {
|
|
i -= 1
|
|
if i < 0 || i >= KeyUsage(len(_KeyUsageIndex)-1) {
|
|
return fmt.Sprintf("KeyUsage(%d)", i+1)
|
|
}
|
|
return _KeyUsageName[_KeyUsageIndex[i]:_KeyUsageIndex[i+1]]
|
|
}
|
|
|
|
var _KeyUsageValues = []KeyUsage{1, 2, 3, 4, 5, 6, 7}
|
|
|
|
var _KeyUsageNameToValueMap = map[string]KeyUsage{
|
|
_KeyUsageName[0:7]: 1,
|
|
_KeyUsageName[7:14]: 2,
|
|
_KeyUsageName[14:18]: 3,
|
|
_KeyUsageName[18:24]: 4,
|
|
_KeyUsageName[24:28]: 5,
|
|
_KeyUsageName[28:34]: 6,
|
|
_KeyUsageName[34:49]: 7,
|
|
}
|
|
|
|
// KeyUsageString retrieves an enum value from the enum constants string name.
|
|
// Throws an error if the param is not part of the enum.
|
|
func KeyUsageString(s string) (KeyUsage, error) {
|
|
if val, ok := _KeyUsageNameToValueMap[s]; ok {
|
|
return val, nil
|
|
}
|
|
return 0, fmt.Errorf("%s does not belong to KeyUsage values", s)
|
|
}
|
|
|
|
// KeyUsageValues returns all values of the enum
|
|
func KeyUsageValues() []KeyUsage {
|
|
return _KeyUsageValues
|
|
}
|
|
|
|
// IsAKeyUsage returns "true" if the value is listed in the enum definition. "false" otherwise
|
|
func (i KeyUsage) IsAKeyUsage() bool {
|
|
for _, v := range _KeyUsageValues {
|
|
if i == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|