Skip to content

Commit

Permalink
minor: add MustGenerateRandomBase64 helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Nov 24, 2023
1 parent ab10517 commit f42e953
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/rand"
_ "crypto/sha256" // ignore:lint
_ "crypto/sha512"
"encoding/base64"
"fmt"
"os"
)
Expand Down Expand Up @@ -99,6 +100,19 @@ func MustGenerateRandomString(length int) string {
return string(result)
}

// NoPadding is the base64.NoPadding.
const NoPadding = base64.NoPadding

// MustGenerateRandomBase64 returns a random base64 string based on the passed length.
//
// Usage:
//
// MustGenerateRandomBase64(32, jwt.NoPadding)
func MustGenerateRandomBase64(length int, padding rune) string {
b := MustGenerateRandom(length)
return base64.StdEncoding.WithPadding(padding).EncodeToString(b)
}

//

// MustLoadHMAC accepts a single filename
Expand Down

0 comments on commit f42e953

Please sign in to comment.