Mainly redefine or reused what Terraform did. * allow to used `variables`, `variable` and `local` blocks * import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
36 lines
817 B
Go
36 lines
817 B
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package bcrypt
|
|
|
|
import "encoding/base64"
|
|
|
|
const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
var bcEncoding = base64.NewEncoding(alphabet)
|
|
|
|
func base64Encode(src []byte) []byte {
|
|
n := bcEncoding.EncodedLen(len(src))
|
|
dst := make([]byte, n)
|
|
bcEncoding.Encode(dst, src)
|
|
for dst[n-1] == '=' {
|
|
n--
|
|
}
|
|
return dst[:n]
|
|
}
|
|
|
|
func base64Decode(src []byte) ([]byte, error) {
|
|
numOfEquals := 4 - (len(src) % 4)
|
|
for i := 0; i < numOfEquals; i++ {
|
|
src = append(src, '=')
|
|
}
|
|
|
|
dst := make([]byte, bcEncoding.DecodedLen(len(src)))
|
|
n, err := bcEncoding.Decode(dst, src)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return dst[:n], nil
|
|
}
|