]> ruderich.org/simon Gitweb - nsscash/nsscash.git/commitdiff
nsscash: add support to convert plain files
authorSimon Ruderich <simon@ruderich.org>
Sat, 8 Jun 2019 12:33:58 +0000 (14:33 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sat, 8 Jun 2019 12:33:58 +0000 (14:33 +0200)
For plain files this is just a copy. But it prepares for conversion of
other types in the future.

main.go

diff --git a/main.go b/main.go
index cef6c61d41bfe9dfef0c8995ab25cf8b4762d7c9..db21997fee0cf71bdcfe5ed2836b7b092ea5b10b 100644 (file)
--- a/main.go
+++ b/main.go
@@ -82,15 +82,21 @@ func main() {
                if err != nil {
                        log.Fatal(err)
                }
+               var x bytes.Buffer
+               if t == FileTypePlain {
+                       x.Write(src)
+               } else if t == FileTypePasswd {
                pws, err := ParsePasswds(bytes.NewReader(src))
                if err != nil {
                        log.Fatal(err)
                }
-               var x bytes.Buffer
                err = SerializePasswds(&x, pws)
                if err != nil {
                        log.Fatal(err)
                }
+               } else {
+                       log.Fatalf("unsupported file type %v", t)
+               }
 
                // We must create the file first or deployFile() will abort
                f, err := os.Create(args[3])