From 17eeaeb8b12115d5b699e3a29438e751f15ae8b4 Mon Sep 17 00:00:00 2001 From: Richard Jennings Date: Fri, 3 May 2024 08:48:28 +0100 Subject: [PATCH] bugfix default array, generated key, docs (#5) --- README.md | 3 +-- cmd/build.go | 7 +++---- pkg/precrypt/precrypt.go | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 278e9b2..be4ff34 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,12 @@ precrypt --html example/index.html --css example/style.css --js example/index.js ## Library Usage ``` -key := precrypt.Render(precrypt.RenderOptions{ +err := precrypt.Render(precrypt.RenderOptions{ HtmlFiles: []string{"example/index.html"}, CssFiles: []string{"example/style.css"}, JsFiles: []string{"example/index.js"}, Key: []byte{"passphrasewhichneedstobe32bytes!"}, Out: os.Stdout, - } ``` diff --git a/cmd/build.go b/cmd/build.go index c7864b3..f38f7b4 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -46,9 +46,8 @@ var build = &cobra.Command{ fmt.Println(err) os.Exit(1) } - opts.Key = make([]byte, hex.EncodedLen(len(bytes))) - hex.Encode(opts.Key, bytes) - fmt.Println(string(opts.Key)) + opts.Key = bytes + fmt.Println(hex.EncodeToString(bytes)) } if err := precrypt.Render(opts); err != nil { fmt.Println(err) @@ -61,7 +60,7 @@ func init() { build.Flags().StringArrayVar(&htmlFiles, "html", []string{}, "--html ,") build.Flags().StringArrayVar(&cssFiles, "css", []string{}, "--css ,") build.Flags().StringArrayVar(&jsFiles, "js", []string{}, "--js ,") - build.Flags().StringVar(&key, "key", "", "--key 32byteslong") + build.Flags().StringVar(&key, "key", "", "--key hexencoded32bytes") } func Execute() { diff --git a/pkg/precrypt/precrypt.go b/pkg/precrypt/precrypt.go index 28dd5ec..46cc03b 100644 --- a/pkg/precrypt/precrypt.go +++ b/pkg/precrypt/precrypt.go @@ -35,6 +35,7 @@ type RenderOptions struct { func Render(opts RenderOptions) error { var err error + if len(opts.Key) != 32 { return errors.New("invalid key length") } @@ -78,7 +79,7 @@ func Render(opts RenderOptions) error { } func encryptFiles(paths []string, key []byte) ([]string, error) { - var ret []string + ret := []string{} for _, v := range paths { b, err := encryptFile(v, key) if err != nil {