Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] Add blake3 to the template functions #2693

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .license-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ unrestricted_licenses:
- BSD-2-Clause
- 0BSD
- WTFPL
- CC0-1.0
reciprocal_licenses:
- MPL-2.0
- MPL-2.0-no-copyleft-exception
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ require (
github.com/jwalton/go-supportscolor v1.2.0 // indirect
github.com/kjk/lzmadec v0.0.0-20210713164611-19ac3ee91a71 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
Expand All @@ -82,6 +83,7 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ github.com/kjk/lzmadec v0.0.0-20210713164611-19ac3ee91a71 h1:TYp9Fj0apeZMWentXRa
github.com/kjk/lzmadec v0.0.0-20210713164611-19ac3ee91a71/go.mod h1:2zRkQCuw/eK6cqkYAeNqyBU7JKa2Gcq40BZ9GSJbmfE=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE=
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down Expand Up @@ -194,6 +196,10 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zalando/go-keyring v0.2.3 h1:v9CUu9phlABObO4LPWycf+zwMG7nlbb3t/B5wa97yms=
github.com/zalando/go-keyring v0.2.3/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk=
github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/blake3 v0.2.3 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg=
github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ=
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
Expand Down
6 changes: 6 additions & 0 deletions internal/hashsum/hashsums.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"crypto/sha256"
"crypto/sha512"
"fmt"

"github.com/zeebo/blake3"
)

func MD5Hex(in string) string {
Expand All @@ -23,3 +25,7 @@ func SHA256Hex(in string) string {
func SHA512Hex(in string) string {
return fmt.Sprintf("%x", sha512.Sum512([]byte(in)))
}

func Blake3Hex(in string) string {
return fmt.Sprintf("%x", blake3.Sum256([]byte(in)))
}
9 changes: 9 additions & 0 deletions internal/tpl/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
FuncSha1sum = "sha1sum"
FuncSha256sum = "sha256sum"
FuncSha512sum = "sha512sum"
FuncBlake3 = "blake3"
FuncMd5Crypt = "md5crypt"
FuncSSHA = "ssha"
FuncSSHA256 = "ssha256"
Expand Down Expand Up @@ -67,6 +68,12 @@ func sha512sum() func(...string) (string, error) {
}
}

func blake3sum() func(...string) (string, error) {
return func(s ...string) (string, error) {
return hashsum.Blake3Hex(s[0]), nil
}
}

// saltLen tries to parse the given string into a numeric salt length.
func saltLen(s []string) uint8 {
if len(s) < 2 {
Expand Down Expand Up @@ -379,6 +386,7 @@ func funcMap(ctx context.Context, kv kvstore) template.FuncMap {
FuncSha1sum: sha1sum(),
FuncSha256sum: sha256sum(),
FuncSha512sum: sha512sum(),
FuncBlake3: blake3sum(),
FuncMd5Crypt: md5cryptFunc(),
FuncSSHA: sshaFunc(),
FuncSSHA256: ssha256Func(),
Expand All @@ -400,6 +408,7 @@ func PublicFuncMap() template.FuncMap {
FuncSha1sum: sha1sum(),
FuncSha256sum: sha256sum(),
FuncSha512sum: sha512sum(),
FuncBlake3: blake3sum(),
FuncMd5Crypt: md5cryptFunc(),
FuncSSHA: sshaFunc(),
FuncSSHA256: ssha256Func(),
Expand Down
1 change: 1 addition & 0 deletions internal/tpl/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Example() { //nolint:testableexamples
Password-value of the new entry: {{ .Content }}
Md5sum of the new password: {{ .Content | md5sum }}
Sha1sum of the new password: {{ .Content | sha1sum }}
Blake3sum of the new password: {{ .Content | blake3sum }}
Md5crypt of the new password: {{ .Content | md5crypt }}
SSHA of the new password: {{ .Content | ssha }}
SSHA256 of the new password: {{ .Content | ssha256 }}
Expand Down