refactor: format code with interface, Close #22

This commit is contained in:
ᴍᴏᴏɴD4ʀᴋ
2020-08-01 02:36:44 +08:00
parent 5936e17e26
commit 2b2cc13cff
9 changed files with 637 additions and 703 deletions
+8 -10
View File
@@ -4,7 +4,6 @@ import (
"bytes"
"crypto/sha1"
"errors"
"hack-browser-data/log"
"os/exec"
"golang.org/x/crypto/pbkdf2"
@@ -26,38 +25,37 @@ var (
"chrome": {
ProfilePath: chromeProfilePath,
Name: chromeName,
New: decryptChromium,
New: NewChromium,
},
"edge": {
ProfilePath: edgeProfilePath,
Name: edgeName,
New: decryptChromium,
New: NewChromium,
},
"firefox": {
ProfilePath: fireFoxProfilePath,
Name: firefoxName,
New: decryptFirefox,
New: NewFirefox,
},
}
)
func (c *chromium) InitSecretKey() error {
func (c *Chromium) InitSecretKey() error {
var (
cmd *exec.Cmd
stdout, stderr bytes.Buffer
)
//➜ security find-generic-password -wa 'Chrome'
cmd = exec.Command("security", "find-generic-password", "-wa", c.Name)
cmd = exec.Command("security", "find-generic-password", "-wa", c.name)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
log.Error(err)
return err
}
if stderr.Len() > 0 {
err = errors.New(stderr.String())
log.Error(err)
return err
}
temp := stdout.Bytes()
chromeSecret := temp[:len(temp)-1]
@@ -67,6 +65,6 @@ func (c *chromium) InitSecretKey() error {
var chromeSalt = []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
c.SecretKey = key
return err
c.secretKey = key
return nil
}