Skip to content

Commit

Permalink
bugfix default array, generated key, docs (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardjennings authored May 3, 2024
1 parent 46601e4 commit 17eeaeb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
```

Expand Down
7 changes: 3 additions & 4 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -61,7 +60,7 @@ func init() {
build.Flags().StringArrayVar(&htmlFiles, "html", []string{}, "--html <file1.html>,<file2.html>")
build.Flags().StringArrayVar(&cssFiles, "css", []string{}, "--css <file1.css>,<file2.css>")
build.Flags().StringArrayVar(&jsFiles, "js", []string{}, "--js <file1.js>,<file2.js>")
build.Flags().StringVar(&key, "key", "", "--key 32byteslong")
build.Flags().StringVar(&key, "key", "", "--key hexencoded32bytes")
}

func Execute() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/precrypt/precrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 17eeaeb

Please sign in to comment.