Skip to content

Commit

Permalink
Add debugging prints
Browse files Browse the repository at this point in the history
  • Loading branch information
DTLP committed Sep 19, 2023
1 parent 0642bce commit f7a2007
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions strongbox-lib/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,30 @@ func Diff(filename string) {
}

func Clean(r io.Reader, w io.Writer, filename string) {
fmt.Println("\nfunc clean()")
// Read the file, fail on error
in, err := io.ReadAll(r)
if err != nil {
log.Fatal(err)
}
fmt.Println("in: ", in)
inString := string(in)
fmt.Println("inString: ", inString)
fmt.Println("prefix", prefix)
// Check the file is plaintext, if its an encrypted strongbox file, copy as is, and exit 0
if bytes.HasPrefix(in, prefix) {
fmt.Println("if bytes.HasPrefix(in, prefix)")
_, err = io.Copy(w, bytes.NewReader(in))
if err != nil {
log.Fatal(err)
}
return
}
// File is plaintext and needs to be encrypted, get the key, fail on error
fmt.Println("filename: ", filename)
key, err := keyLoader(filename)
fmt.Println("key: ", key)
fmt.Println("err: ", err)
if err != nil {
log.Fatal(err)
}
Expand All @@ -157,6 +166,7 @@ func Clean(r io.Reader, w io.Writer, filename string) {
if err != nil {
log.Fatal(err)
}
fmt.Println("END OF CLEAN()")
}

// Called by git on `git checkout`
Expand Down Expand Up @@ -372,17 +382,24 @@ func decrypt(enc []byte, priv []byte) ([]byte, error) {

// key returns private key and error
func Key(filename string) ([]byte, error) {
fmt.Println("\nfunc Key()")
fmt.Println("filename: ", filename)
keyID, err := findKey(filename)
fmt.Println("keyID: ", keyID)
fmt.Println("err: ", err)
if err != nil {
return []byte{}, err
}

err = kr.Load()
fmt.Println("err: ", err)
if err != nil {
return []byte{}, err
}

key, err := kr.Key(keyID)
fmt.Println("key: ", key)
fmt.Println("err: ", err)
if err != nil {
return []byte{}, err
}
Expand All @@ -391,10 +408,13 @@ func Key(filename string) ([]byte, error) {
}

func findKey(filename string) ([]byte, error) {
fmt.Println("\nfunc findKey()")
path := filepath.Dir(filename)
fmt.Println("path: ", path)
for {
if fi, err := os.Stat(path); err == nil && fi.IsDir() {
keyFilename := filepath.Join(path, ".strongbox-keyid")
fmt.Println("keyFilename:", keyFilename)
if keyFile, err := os.Stat(keyFilename); err == nil && !keyFile.IsDir() {
return readKey(keyFilename)
}
Expand Down
3 changes: 3 additions & 0 deletions strongbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ func testKeyLoader(string) ([]byte, error) {
}

func TestMultipleClean(t *testing.T) {
fmt.Println("func TestMultipleClean()")
assert := assert.New(t)

var cleaned bytes.Buffer
fmt.Println("cleaned: ", cleaned)
fmt.Println("bytes.NewReader: ", bytes.NewReader(plain))
strongbox.Clean(bytes.NewReader(plain), &cleaned, "")

var doubleCleaned bytes.Buffer
Expand Down

0 comments on commit f7a2007

Please sign in to comment.