-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.go
42 lines (39 loc) · 1006 Bytes
/
get.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
package main
import (
"github.com/king-jam/git-credential-crypt-store/backend"
"github.com/king-jam/git-credential-crypt-store/crypto"
"github.com/king-jam/git-credential-crypt-store/dialogs"
)
func lookupCredentials(db backend.CryptStoreInterface, credentials *Credential) error {
var s *backend.StorageContainer
s, err := db.GetStorageContainer()
if err != nil {
return err
}
// iterate to see if we already have these credentials stored
for _, elem := range s.CredentialURLs {
c := new(Credential)
err := parseCredentialURL(elem, c)
if err != nil {
return err
}
if CredentialsMatch(credentials, c) {
password, err := dialogs.PasswordBox(c.Username)
if err != nil {
return err
}
cipher, err := crypto.NewCipher(password)
if err != nil {
return err
}
decryptedPassword, err := cipher.Decrypt([]byte(c.Password))
if err != nil {
return err
}
c.Password = string(decryptedPassword)
c.PrintToStdOut()
return nil
}
}
return nil
}