diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2023-09-10 16:09:48 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-10 16:09:48 +1000 |
| commit | 55e19f85ca05154fc3a3402dc330860843d283c2 (patch) | |
| tree | ab842d8463ef7370643d35fe683e370459a7f5a4 /internal/configuration/decode_hooks.go | |
| parent | 6b0e263d4f6ceb75a65d2b708f28f60dd35040b6 (diff) | |
test: fix cert testing (#5982)
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'internal/configuration/decode_hooks.go')
| -rw-r--r-- | internal/configuration/decode_hooks.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/internal/configuration/decode_hooks.go b/internal/configuration/decode_hooks.go index 05dbba95f..2a6c5ff93 100644 --- a/internal/configuration/decode_hooks.go +++ b/internal/configuration/decode_hooks.go @@ -2,6 +2,7 @@ package configuration import ( "crypto/ecdsa" + "crypto/ed25519" "crypto/rsa" "crypto/x509" "fmt" @@ -537,7 +538,9 @@ func StringToCryptographicKeyHookFunc() mapstructure.DecodeHookFuncType { } } -// StringToPrivateKeyHookFunc decodes strings to rsa.PrivateKey's. +// StringToPrivateKeyHookFunc decodes strings to rsa.PrivateKey's and ecdsa.PrivateKey's. +// +//nolint:gocyclo func StringToPrivateKeyHookFunc() mapstructure.DecodeHookFuncType { return func(f reflect.Type, t reflect.Type, data any) (value any, err error) { if f.Kind() != reflect.String { @@ -550,6 +553,7 @@ func StringToPrivateKeyHookFunc() mapstructure.DecodeHookFuncType { expectedTypeRSA := reflect.TypeOf(rsa.PrivateKey{}) expectedTypeECDSA := reflect.TypeOf(ecdsa.PrivateKey{}) + expectedTypeEd25519 := reflect.TypeOf(ed25519.PrivateKey{}) var ( i any @@ -575,6 +579,14 @@ func StringToPrivateKeyHookFunc() mapstructure.DecodeHookFuncType { } expectedType = expectedTypeECDSA + case expectedTypeEd25519: + var result *ed25519.PrivateKey + + if dataStr == "" { + return result, nil + } + + expectedType = expectedTypeEd25519 default: return data, nil } @@ -600,6 +612,12 @@ func StringToPrivateKeyHookFunc() mapstructure.DecodeHookFuncType { } return r, nil + case ed25519.PrivateKey: + if expectedType != expectedTypeEd25519 { + return nil, fmt.Errorf(errFmtDecodeHookCouldNotParseBasic, "*", expectedType, fmt.Errorf("the data is for a %T not a *%s", r, expectedType)) + } + + return &r, nil default: return nil, fmt.Errorf(errFmtDecodeHookCouldNotParseBasic, "*", expectedType, fmt.Errorf("the data is for a %T not a *%s", r, expectedType)) } |
