types/key: add NodePrivate.Raw32 and DiscoPrivateFromRaw32
Raw byte accessors for key types, mirroring existing patterns (NodePublic.Raw32 and DiscoPublicFromRaw32 already exist). NodePrivate.Raw32 returns the raw 32 bytes of a node private key. DiscoPrivateFromRaw32 parses a 32-byte raw value as a DiscoPrivate. Updates tailscale/corp#24454 Change-Id: Ibc08bed14ab359eddefbebd811c375b6365c7919 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
32adca78f1
commit
525f7a1e47
@@ -42,6 +42,16 @@ func NewDisco() DiscoPrivate {
|
||||
return ret
|
||||
}
|
||||
|
||||
// DiscoPrivateFromRaw32 parses a 32-byte raw value as a DiscoPrivate.
|
||||
func DiscoPrivateFromRaw32(raw mem.RO) DiscoPrivate {
|
||||
if raw.Len() != 32 {
|
||||
panic("input has wrong size")
|
||||
}
|
||||
var ret DiscoPrivate
|
||||
raw.Copy(ret.k[:])
|
||||
return ret
|
||||
}
|
||||
|
||||
// IsZero reports whether k is the zero value.
|
||||
func (k DiscoPrivate) IsZero() bool {
|
||||
return k.Equal(DiscoPrivate{})
|
||||
|
||||
@@ -61,6 +61,9 @@ func NewNode() NodePrivate {
|
||||
return ret
|
||||
}
|
||||
|
||||
// Raw32 returns k as 32 raw bytes.
|
||||
func (k NodePrivate) Raw32() [32]byte { return k.k }
|
||||
|
||||
// NodePrivateFromRaw32 parses a 32-byte raw value as a NodePrivate.
|
||||
//
|
||||
// Deprecated: only needed to cast from legacy node private key types,
|
||||
|
||||
Reference in New Issue
Block a user