Files
opentf/internal/encryption/method/aesgcm/panic.go
Janos fa638907f1 Fixes #1169: AES-GCM implementation (#1291)
Signed-off-by: Janos <86970079+janosdebugs@users.noreply.github.com>
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: James Humphries <James@james-humphries.co.uk>
Co-authored-by: James Humphries <jamesh@spacelift.io>
Co-authored-by: Serdar Dalgıç <serdardalgic@users.noreply.github.com>
Co-authored-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2024-03-07 10:24:37 +00:00

27 lines
562 B
Go

package aesgcm
import "fmt"
// handlePanic runs the specified function and returns its result value or returned error. If a panic occurs, it returns the
// panic as an error.
func handlePanic(f func() ([]byte, error)) (result []byte, err error) {
result, e := func() ([]byte, error) {
defer func() {
var ok bool
e := recover()
if e == nil {
return
}
if err, ok = e.(error); !ok {
// In case the panic is not an error
err = fmt.Errorf("%v", e)
}
}()
return f()
}()
if err != nil {
return nil, err
}
return result, e
}