Skip to content

Commit

Permalink
Added cryptographically secure pseudorandom base64 string
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilyes512 committed Jul 27, 2018
1 parent b306093 commit 81b975d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/template/functions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package template

import (
"crypto/rand"
"encoding/base64"
"fmt"
"os"
"os/user"
Expand Down Expand Up @@ -95,6 +97,18 @@ var (

return res
},

// generate a random base64 string based on random bytes of length n
"randomBase64": func(length int) string {
b := make([]byte, length)
_, err := rand.Read(b)

if err != nil {
return fmt.Sprintf("failed to generate randomBase64: %s", err)
}

return base64.StdEncoding.EncodeToString(b)
},
}

// Options contain the default options for the template execution.
Expand Down

0 comments on commit 81b975d

Please sign in to comment.