Files
smt/models/key.go
Nathan Coad 484acd1822
All checks were successful
continuous-integration/drone/push Build is passing
more implementation of runtime unlock
2023-12-28 11:14:16 +11:00

31 lines
717 B
Go

package models
import "errors"
// TODO: Look at using shamir's secret sharing to distribute components of the secret key
var secretKey []byte
var secretReceived bool
func ReceiveKey(key string) error {
// confirm that the key is 32 bytes long exactly
if len(key) != 32 {
return errors.New("secret key provided is not exactly 32 bytes long")
}
// Store the secret key so that we can access it when encrypting/decrypting
secretKey = []byte(key)
secretReceived = true
return nil
}
func ProvideKey() ([]byte, error) {
// Provide the key when needed to decrypt/encrypt stored secrets
if secretReceived {
return secretKey, nil
} else {
return nil, errors.New("secret key has not been received")
}
}