Debian Codegraph @

helper.go

raw symbols SCIP
1 package machineid
2
3 import (
4 "crypto/hmac"
5 "crypto/sha256"
6 "encoding/hex"
7 "io"
8 "io/ioutil"
9 "os"
10 "os/exec"
11 "strings"
12 )
13
14 // run wraps `exec.Command` with easy access to stdout and stderr.
15 func run(stdout, stderr io.Writer, cmd string, args ...string) error {
16 c := exec.Command(cmd, args...)
17 c.Stdin = os.Stdin
18 c.Stdout = stdout
19 c.Stderr = stderr
20 return c.Run()
21 }
22
23 // protect calculates HMAC-SHA256 of the application ID, keyed by the machine ID and returns a hex-encoded string.
24 func protect(appID, id string) string {
25 mac := hmac.New(sha256.New, []byte(id))
26 mac.Write([]byte(appID))
27 return hex.EncodeToString(mac.Sum(nil))
28 }
29
30 func readFile(filename string) ([]byte, error) {
31 return ioutil.ReadFile(filename)
32 }
33
34 func trim(s string) string {
35 return strings.TrimSpace(strings.Trim(s, "\n"))
36 }