mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 20:05:17 +03:00
refactor: change structure project
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package hasher
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/lorsanstand/HomeOps-Hub/shared/domain"
|
||||
)
|
||||
|
||||
func newSalt(n int) ([]byte, error) {
|
||||
b := make([]byte, n)
|
||||
_, err := rand.Read(b)
|
||||
return b, err
|
||||
}
|
||||
|
||||
func MakeID(info domain.HostInfo, AgentName string) (string, error) {
|
||||
salt, err := newSalt(10)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
s := fmt.Sprintf("v1|host=%s|distro=%s|name=%s|", info.Hostname, info.Arch, AgentName)
|
||||
h := sha256.Sum256(append([]byte(s), salt...))
|
||||
return hex.EncodeToString(h[:16]), nil
|
||||
}
|
||||
Reference in New Issue
Block a user