mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-06 04:36:15 +02:00
types/key: add database scan/value to publickeys
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
3bd382f369
commit
43a73a856d
@ -5,6 +5,8 @@ package key
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"go4.org/mem"
|
||||
@ -142,6 +144,29 @@ func (k *DiscoPublic) UnmarshalText(b []byte) error {
|
||||
return parseHex(k.k[:], mem.B(b), mem.S(discoPublicHexPrefix))
|
||||
}
|
||||
|
||||
func (k DiscoPublic) Value() (driver.Value, error) {
|
||||
return k.MarshalText()
|
||||
}
|
||||
|
||||
func (k *DiscoPublic) Scan(value interface{}) error {
|
||||
var val []byte
|
||||
switch value.(type) {
|
||||
case string:
|
||||
val = []byte(value.(string))
|
||||
case []byte:
|
||||
val = value.([]byte)
|
||||
default:
|
||||
return errors.New("Incompatible type for DiscoPublic")
|
||||
}
|
||||
|
||||
err := k.UnmarshalText(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type DiscoShared struct {
|
||||
_ structs.Incomparable // because == isn't constant-time
|
||||
k [32]byte
|
||||
|
||||
@ -6,7 +6,9 @@ package key
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/subtle"
|
||||
"database/sql/driver"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
||||
"go4.org/mem"
|
||||
"golang.org/x/crypto/curve25519"
|
||||
@ -262,3 +264,26 @@ func (k MachinePublic) MarshalText() ([]byte, error) {
|
||||
func (k *MachinePublic) UnmarshalText(b []byte) error {
|
||||
return parseHex(k.k[:], mem.B(b), mem.S(machinePublicHexPrefix))
|
||||
}
|
||||
|
||||
func (k MachinePublic) Value() (driver.Value, error) {
|
||||
return k.MarshalText()
|
||||
}
|
||||
|
||||
func (k *MachinePublic) Scan(value interface{}) error {
|
||||
var val []byte
|
||||
switch value.(type) {
|
||||
case string:
|
||||
val = []byte(value.(string))
|
||||
case []byte:
|
||||
val = value.([]byte)
|
||||
default:
|
||||
return errors.New("Incompatible type for MachinePublic")
|
||||
}
|
||||
|
||||
err := k.UnmarshalText(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/subtle"
|
||||
"database/sql/driver"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -379,3 +380,26 @@ func (k NodePublic) WireGuardGoString() string {
|
||||
b[second+3] = b64((k.k[31] << 2) & 63)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (k NodePublic) Value() (driver.Value, error) {
|
||||
return k.MarshalText()
|
||||
}
|
||||
|
||||
func (k *NodePublic) Scan(value interface{}) error {
|
||||
var val []byte
|
||||
switch value.(type) {
|
||||
case string:
|
||||
val = []byte(value.(string))
|
||||
case []byte:
|
||||
val = value.([]byte)
|
||||
default:
|
||||
return errors.New("Incompatible type for NodePublic")
|
||||
}
|
||||
|
||||
err := k.UnmarshalText(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user