aboutsummaryrefslogtreecommitdiff
path: root/gocryptfs-xray/paths_ctlsock.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-05-09 19:11:06 +0200
committerJakob Unterwurzacher2020-05-09 19:11:06 +0200
commit24554b11f773cd6c944b8be2f661962867897520 (patch)
treec2e36811d66a77dc9b617cc4a6de20632a48e2ea /gocryptfs-xray/paths_ctlsock.go
parent171b1eac91263cc8896506321ce686f17cc66314 (diff)
gocryptfs-xray: integrate ctlsock path encryption/decryption
Implementation seems to work ok, but is missing tests and documentation for now. I will only delete ctlsock-encrypt.bash when both are done. https://github.com/rfjakob/gocryptfs/issues/416
Diffstat (limited to 'gocryptfs-xray/paths_ctlsock.go')
-rw-r--r--gocryptfs-xray/paths_ctlsock.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/gocryptfs-xray/paths_ctlsock.go b/gocryptfs-xray/paths_ctlsock.go
new file mode 100644
index 0000000..3c69ec3
--- /dev/null
+++ b/gocryptfs-xray/paths_ctlsock.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+
+ "github.com/rfjakob/gocryptfs/ctlsock"
+)
+
+func decryptPaths(socketPath string) {
+ var req ctlsock.RequestStruct
+ transformPaths(socketPath, &req, &req.DecryptPath)
+}
+
+func encryptPaths(socketPath string) {
+ var req ctlsock.RequestStruct
+ transformPaths(socketPath, &req, &req.EncryptPath)
+}
+
+func transformPaths(socketPath string, req *ctlsock.RequestStruct, in *string) {
+ c, err := ctlsock.New(socketPath)
+ if err != nil {
+ fmt.Printf("fatal: %v\n", err)
+ os.Exit(1)
+ }
+ line := 0
+ scanner := bufio.NewScanner(os.Stdin)
+ for scanner.Scan() {
+ line++
+ *in = scanner.Text()
+ resp, err := c.Query(req)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error at input line %d %q: %v\n", line, *in, err)
+ continue
+ }
+ if resp.WarnText != "" {
+ fmt.Fprintf(os.Stderr, "warning at input line %d %q: %v\n", line, *in, resp.WarnText)
+ }
+ fmt.Println(resp.Result)
+ }
+ os.Exit(0)
+}