-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (52 loc) · 1.25 KB
/
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
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"math/rand"
"os"
"time"
"github.com/jmuldoon/go-keychain/arguments"
"github.com/jmuldoon/go-keychain/generate"
"github.com/jmuldoon/go-keychain/security"
)
// Exit Codes
const (
ExitArgParseErr = 0 + iota
ExitWriteErr
ExitReadErr
)
func main() {
args := &arguments.Args{}
// commandLine := flag.NewFlagSet(os.Args[0], ExitOnError)
// if err := arguments.Parse(args, commandLine); err != nil {
// TODO: follow up with the adjustment to fully controlled system as deailed above.
if err := arguments.Parse(args); err != nil {
fmt.Println(err)
os.Exit(ExitArgParseErr)
}
if *args.Generate > 0 {
src := rand.NewSource(time.Now().UnixNano())
*args.Data = generate.RandStringBytesMask(src, *args.Generate)
}
kcitem := &security.Item{
Account: *args.Account,
Group: *args.Group,
Data: []byte(*args.Data),
Label: *args.Label,
Service: *args.Service,
}
// create interface struct
extKeychain := &security.ExternalKeychain{}
if *args.Read {
plaintextPassword, err := kcitem.Read(extKeychain)
if err != nil {
fmt.Println(err)
os.Exit(ExitReadErr)
}
fmt.Println(plaintextPassword)
} else {
if err := kcitem.Write(extKeychain); err != nil {
fmt.Println(err)
os.Exit(ExitWriteErr)
}
}
}