Skip to content

Commit

Permalink
Fix decrypt not parsing rot-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
thequailman committed Mar 19, 2024
1 parent ed785fc commit 80d8a07
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions go/cmdDecrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"context"
"os"
"strings"

"github.com/candiddev/shared/go/cli"
"github.com/candiddev/shared/go/cryptolib"
Expand All @@ -16,19 +18,26 @@ func cmdDecrypt() cli.Command[*cfg] {
},
Usage: "Decrypt a value or unwrap a KDF value and print it to stdout.",
Run: func(ctx context.Context, args []string, _ cli.Flags, c *cfg) errs.Err {
c.decryptKeysEncrypted(ctx)

value := args[1]

if value == "-" {
value = string(cli.ReadStdin())
}

f, err := os.ReadFile(value)
if err == nil {
value = strings.TrimSpace(string(f))
}

ev, err := cryptolib.ParseEncryptedValue(value)
if err != nil {
return logger.Error(ctx, errs.ErrReceiver.Wrap(err))
}

if ev.KDF == "" {
c.decryptKeysEncrypted(ctx)
}

v, err := ev.Decrypt(c.keys.Keys())
if err != nil {
return logger.Error(ctx, errs.ErrReceiver.Wrap(err))
Expand Down

0 comments on commit 80d8a07

Please sign in to comment.