feat: introducing support for private and public x25519 keys#49
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces X25519PrivateKey and X25519PublicKey types to the xtypes package, enabling the use of X25519 keys within configuration structs. These types support various input formats such as PEM, hex, and raw bytes. The review feedback highlights a typo in an error message, suggests that public keys should not be redacted in usage information, and recommends proper error handling within test helper functions.
| func (d *X25519PublicKey) GetDefaultValue() (string, error) { | ||
| // TODO show the public key | ||
| return "<secret>", nil | ||
| } |
There was a problem hiding this comment.
Public keys are not secret, so GetDefaultValue should not return "<secret>" as this is misleading. The TODO comment on line 79 also indicates this needs to be addressed.
A better approach would be to return a representation of the public key. Since this is for usage information, a concise format like hex encoding is suitable. If no default value is set, an empty string should be returned.
func (d *X25519PublicKey) GetDefaultValue() (string, error) {
if d.DefaultValue == nil {
return "", nil
}
return hex.EncodeToString(d.DefaultValue.Bytes()), nil
}| } | ||
| pubK, err := x509.ParsePKIXPublicKey(pemBlock.Bytes) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error decoding PEM block as ANS.1 public key: %w", err) |
There was a problem hiding this comment.
| newPriv, _ := ecdh.X25519().GenerateKey(rand.Reader) | ||
| pub = newPriv.PublicKey() |
There was a problem hiding this comment.
The error returned by ecdh.X25519().GenerateKey(rand.Reader) is ignored. While errors from rand.Reader are rare, it is best practice to handle all errors, even in test helpers, to make the test suite more robust. Please check the error and fail the test if it is not nil.
newPriv, err := ecdh.X25519().GenerateKey(rand.Reader)
if err != nil {
t.Fatalf("failed to generate X25519 private key: %v", err)
}
pub = newPriv.PublicKey()
No description provided.