-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (46 loc) · 856 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"io/ioutil"
"log"
"os"
"github.com/abennett/cryptlog/cryptloggers"
)
const cryptLogPassEnv = "CRYPTLOG_PASS"
func main() {
password, ok := os.LookupEnv(cryptLogPassEnv)
if !ok {
log.Fatalf("missing %s envvar", cryptLogPassEnv)
}
if len(os.Args) != 2 {
log.Fatal("wrong number of arguments")
}
fcl, err := cryptloggers.OpenFile(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer fcl.Close()
cl, err := New(password)
if err != nil {
log.Fatal(err)
}
stat, err := os.Stdin.Stat()
if err != nil {
log.Fatal(err)
}
if stat.Mode()&os.ModeCharDevice == 0 {
input, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
err = cl.Append(fcl, input)
if err != nil {
log.Fatal(err)
}
return
}
b, err := cl.Decrypt(fcl)
if err != nil {
log.Fatal(err)
}
os.Stdout.Write(b)
}