aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--device/noise-types.go9
-rw-r--r--device/uapi.go2
2 files changed, 10 insertions, 1 deletions
diff --git a/device/noise-types.go b/device/noise-types.go
index 6b1f16f..a1976ff 100644
--- a/device/noise-types.go
+++ b/device/noise-types.go
@@ -52,6 +52,15 @@ func (key *NoisePrivateKey) FromHex(src string) (err error) {
return
}
+func (key *NoisePrivateKey) FromMaybeZeroHex(src string) (err error) {
+ err = loadExactHex(key[:], src)
+ if key.IsZero() {
+ return
+ }
+ key.clamp()
+ return
+}
+
func (key NoisePrivateKey) ToHex() string {
return hex.EncodeToString(key[:])
}
diff --git a/device/uapi.go b/device/uapi.go
index 999eeb5..72611ab 100644
--- a/device/uapi.go
+++ b/device/uapi.go
@@ -138,7 +138,7 @@ func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError {
switch key {
case "private_key":
var sk NoisePrivateKey
- err := sk.FromHex(value)
+ err := sk.FromMaybeZeroHex(value)
if err != nil {
logError.Println("Failed to set private_key:", err)
return &IPCError{ipc.IpcErrorInvalid}