Skip to content

Commit

Permalink
Rename types to be consistent with other code
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmaguire committed Dec 5, 2024
1 parent 5e0456d commit c1b65ed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestDoUpdate(t *testing.T) {
require.NoError(t, err)

// convert privkey to private key
pubkey, err := keys.MarshalEd25519HostPublicKey(creds.PrivateKey.Public().Unwrap().(ed25519.PublicKey))
pubkey, err := keys.MarshalHostEd25519PublicKey(creds.PrivateKey.Public().Unwrap().(ed25519.PublicKey))
require.NoError(t, err)

// make sure all credential values were set
Expand Down Expand Up @@ -395,7 +395,7 @@ func TestDoUpdate_P256(t *testing.T) {
require.NoError(t, err)

// convert privkey to private key
pubkey, err := keys.MarshalP256HostPublicKey(creds.PrivateKey.Public().Unwrap().(*ecdsa.PublicKey))
pubkey, err := keys.MarshalHostP256PublicKey(creds.PrivateKey.Public().Unwrap().(*ecdsa.PublicKey))
require.NoError(t, err)

// make sure all credential values were set
Expand Down
4 changes: 2 additions & 2 deletions dnapitest/dnapitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (s *Server) SetCurve(curve message.NetworkCurve) {

func (s *Server) SetEdPubkey(edPubkeyPEM []byte) error {
// hard failure, return
edPubkey, rest, err := keys.UnmarshalEd25519HostPublicKey(edPubkeyPEM)
edPubkey, rest, err := keys.UnmarshalHostEd25519PublicKey(edPubkeyPEM)
if err != nil {
return fmt.Errorf("failed to unmarshal ed pubkey: %w", err)
}
Expand All @@ -138,7 +138,7 @@ func (s *Server) SetEdPubkey(edPubkeyPEM []byte) error {

func (s *Server) SetP256Pubkey(p256PubkeyPEM []byte) error {
// hard failure, return
pubkey, rest, err := keys.UnmarshalP256HostPublicKey(p256PubkeyPEM)
pubkey, rest, err := keys.UnmarshalHostP256PublicKey(p256PubkeyPEM)
if err != nil {
return fmt.Errorf("failed to unmarshal P256 pubkey: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions keys/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (k Ed25519PublicKey) Unwrap() interface{} {
}

func (k Ed25519PublicKey) MarshalPEM() ([]byte, error) {
return MarshalEd25519HostPublicKey(k.PublicKey)
return MarshalHostEd25519PublicKey(k.PublicKey)
}

// P256PublicKey is a wrapper around an ECDSA public key that implements the
Expand All @@ -38,7 +38,7 @@ func (k P256PublicKey) Unwrap() interface{} {
}

func (k P256PublicKey) MarshalPEM() ([]byte, error) {
return MarshalP256HostPublicKey(k.PublicKey)
return MarshalHostP256PublicKey(k.PublicKey)
}

// Ed25519PrivateKey is a wrapper around an Ed25519 private key that implements
Expand All @@ -56,7 +56,7 @@ func (k Ed25519PrivateKey) Unwrap() interface{} {
}

func (k Ed25519PrivateKey) MarshalPEM() ([]byte, error) {
return MarshalEd25519HostPrivateKey(k.PrivateKey)
return MarshalHostEd25519PrivateKey(k.PrivateKey)
}

func (k Ed25519PrivateKey) Public() PublicKey {
Expand All @@ -79,7 +79,7 @@ func (k P256PrivateKey) Unwrap() interface{} {
}

func (k P256PrivateKey) MarshalPEM() ([]byte, error) {
return MarshalP256HostPrivateKey(k.PrivateKey)
return MarshalHostP256PrivateKey(k.PrivateKey)
}

func (k P256PrivateKey) Public() PublicKey {
Expand Down
21 changes: 8 additions & 13 deletions keys/pem.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const HostP256PrivateKeyBanner = "DEFINED HOST P256 PRIVATE KEY"
const NebulaECDSAP256PublicKeyBanner = "NEBULA ECDSA P256 PUBLIC KEY"
const NebulaEd25519PublicKeyBanner = "NEBULA ED25519 PUBLIC KEY"

func MarshalEd25519HostPublicKey(k ed25519.PublicKey) ([]byte, error) {
func MarshalHostEd25519PublicKey(k ed25519.PublicKey) ([]byte, error) {
b, err := x509.MarshalPKIXPublicKey(k)
if err != nil {
return nil, err
Expand All @@ -28,7 +28,7 @@ func MarshalEd25519HostPublicKey(k ed25519.PublicKey) ([]byte, error) {
}), nil
}

func MarshalEd25519HostPrivateKey(k ed25519.PrivateKey) ([]byte, error) {
func MarshalHostEd25519PrivateKey(k ed25519.PrivateKey) ([]byte, error) {
b, err := x509.MarshalPKCS8PrivateKey(k)
if err != nil {
return nil, err
Expand All @@ -39,12 +39,7 @@ func MarshalEd25519HostPrivateKey(k ed25519.PrivateKey) ([]byte, error) {
}), nil
}

func MarshalEd25519NebulaPublicKey(k ed25519.PublicKey) ([]byte, error) {
return pem.EncodeToMemory(&pem.Block{Type: NebulaEd25519PublicKeyBanner, Bytes: k}), nil

}

func MarshalP256HostPublicKey(k *ecdsa.PublicKey) ([]byte, error) {
func MarshalHostP256PublicKey(k *ecdsa.PublicKey) ([]byte, error) {
b, err := x509.MarshalPKIXPublicKey(k)
if err != nil {
return nil, err
Expand All @@ -55,7 +50,7 @@ func MarshalP256HostPublicKey(k *ecdsa.PublicKey) ([]byte, error) {
}), nil
}

func MarshalP256HostPrivateKey(k *ecdsa.PrivateKey) ([]byte, error) {
func MarshalHostP256PrivateKey(k *ecdsa.PrivateKey) ([]byte, error) {
b, err := x509.MarshalECPrivateKey(k)
if err != nil {
return nil, err
Expand All @@ -66,7 +61,7 @@ func MarshalP256HostPrivateKey(k *ecdsa.PrivateKey) ([]byte, error) {
}), nil
}

func UnmarshalEd25519HostPublicKey(b []byte) (ed25519.PublicKey, []byte, error) {
func UnmarshalHostEd25519PublicKey(b []byte) (ed25519.PublicKey, []byte, error) {
k, r := pem.Decode(b)
if k == nil {
return nil, r, fmt.Errorf("input did not contain a valid PEM encoded block")
Expand All @@ -83,7 +78,7 @@ func UnmarshalEd25519HostPublicKey(b []byte) (ed25519.PublicKey, []byte, error)
return pkey.(ed25519.PublicKey), r, nil
}

func UnmarshalEd25519HostPrivateKey(b []byte) (ed25519.PrivateKey, []byte, error) {
func UnmarshalHostEd25519PrivateKey(b []byte) (ed25519.PrivateKey, []byte, error) {
k, r := pem.Decode(b)
if k == nil {
return nil, r, fmt.Errorf("input did not contain a valid PEM encoded block")
Expand All @@ -100,7 +95,7 @@ func UnmarshalEd25519HostPrivateKey(b []byte) (ed25519.PrivateKey, []byte, error
return pkey.(ed25519.PrivateKey), r, nil
}

func UnmarshalP256HostPublicKey(b []byte) (*ecdsa.PublicKey, []byte, error) {
func UnmarshalHostP256PublicKey(b []byte) (*ecdsa.PublicKey, []byte, error) {
k, r := pem.Decode(b)
if k == nil {
return nil, r, fmt.Errorf("input did not contain a valid PEM encoded block")
Expand All @@ -117,7 +112,7 @@ func UnmarshalP256HostPublicKey(b []byte) (*ecdsa.PublicKey, []byte, error) {
return pkey.(*ecdsa.PublicKey), r, nil
}

func UnmarshalP256HostPrivateKey(b []byte) (*ecdsa.PrivateKey, []byte, error) {
func UnmarshalHostP256PrivateKey(b []byte) (*ecdsa.PrivateKey, []byte, error) {
k, r := pem.Decode(b)
if k == nil {
return nil, r, fmt.Errorf("input did not contain a valid PEM encoded block")
Expand Down

0 comments on commit c1b65ed

Please sign in to comment.