From f7a20075ff6b406d64bc5235b1c94e31166d8ca9 Mon Sep 17 00:00:00 2001 From: DTLP Date: Tue, 19 Sep 2023 16:37:20 +0100 Subject: [PATCH] Add debugging prints --- strongbox-lib/main.go | 20 ++++++++++++++++++++ strongbox_test.go | 3 +++ 2 files changed, 23 insertions(+) diff --git a/strongbox-lib/main.go b/strongbox-lib/main.go index 0462edd..1b94c31 100644 --- a/strongbox-lib/main.go +++ b/strongbox-lib/main.go @@ -129,13 +129,19 @@ 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) @@ -143,7 +149,10 @@ func Clean(r io.Reader, w io.Writer, filename string) { 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) } @@ -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` @@ -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 } @@ -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) } diff --git a/strongbox_test.go b/strongbox_test.go index 1d209b3..dd754b9 100644 --- a/strongbox_test.go +++ b/strongbox_test.go @@ -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