Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
[enhancement] Add blake3 to the template functions (gopasspw#2693)
Browse files Browse the repository at this point in the history
* [enhancement] Add blake3 to the template functions

Signed-off-by: Dominik Schulz <[email protected]>

* Add CC0-1.0 to unrestricted licenses.

Signed-off-by: Dominik Schulz <[email protected]>

---------

Signed-off-by: Dominik Schulz <[email protected]>
  • Loading branch information
dominikschulz authored Nov 18, 2023
1 parent edb272a commit e913258
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
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

0 comments on commit e913258

Please sign in to comment.