aboutsummaryrefslogtreecommitdiffstats
path: root/modules/util/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/util/util.go')
-rw-r--r--modules/util/util.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/util/util.go b/modules/util/util.go
index 9d5e6c1e89..cc25539967 100644
--- a/modules/util/util.go
+++ b/modules/util/util.go
@@ -6,6 +6,7 @@ package util
import (
"bytes"
"crypto/rand"
+ "encoding/base64"
"fmt"
"math/big"
"strconv"
@@ -261,3 +262,13 @@ func ToFloat64(number any) (float64, error) {
func ToPointer[T any](val T) *T {
return &val
}
+
+func Base64FixedDecode(encoding *base64.Encoding, src []byte, length int) ([]byte, error) {
+ decoded := make([]byte, encoding.DecodedLen(len(src))+3)
+ if n, err := encoding.Decode(decoded, src); err != nil {
+ return nil, err
+ } else if n != length {
+ return nil, fmt.Errorf("invalid base64 decoded length: %d, expects: %d", n, length)
+ }
+ return decoded[:length], nil
+}