Add EmulatedHostSeed option

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
This commit is contained in:
Ettore Di Giacinto
2022-06-17 14:58:53 +02:00
parent a8efc2a644
commit 89d72d325e

View File

@@ -1,7 +1,9 @@
package tpm package tpm
import ( import (
"hash/fnv"
"net/http" "net/http"
"os"
"github.com/google/go-attestation/attest" "github.com/google/go-attestation/attest"
) )
@@ -67,6 +69,27 @@ func WithCommandChannel(cc attest.CommandChannelTPM20) Option {
} }
} }
func hashit(s string) uint32 {
h := fnv.New32a()
h.Write([]byte(s))
return h.Sum32()
}
func tokenize() int64 {
hostname, err := os.Hostname()
if err != nil {
return 0
}
return int64(hashit(hostname))
}
var EmulatedHostSeed = func() Option {
return func(c *config) error {
c.seed = tokenize()
return nil
}
}
func (c *config) apply(opts ...Option) error { func (c *config) apply(opts ...Option) error {
for _, o := range opts { for _, o := range opts {
if err := o(c); err != nil { if err := o(c); err != nil {