Skip to content

Commit

Permalink
Next review: Fixed casing on error messages for linter | Fixed versio…
Browse files Browse the repository at this point in the history
…n number
  • Loading branch information
horvski committed Dec 13, 2023
1 parent 89db97c commit a27b507
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions crypto/eddsa.go → crypto/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func Ed25519GenerateKey() ([]byte, error) {
_, secret, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, fmt.Errorf("Ed25519GenerateKey: failed to generate EDDSA private key: %w", err)
return nil, fmt.Errorf("generateKey: %w", err)
}
return pemEncodeEdPrivateKey(secret)
}
Expand All @@ -22,7 +22,7 @@ func Ed25519GenerateKey() ([]byte, error) {
// `seed`. Returns error if len(seed) is not ed25519.SeedSize (32).
func Ed25519GenerateKeyFromSeed(seed []byte) ([]byte, error) {
if len(seed) != ed25519.SeedSize {
return nil, fmt.Errorf("Ed25519GenerateKeyFromSeed: incorrect seed size - given: %d wanted %d", len(seed), ed25519.SeedSize)
return nil, fmt.Errorf("generateKeyFromSeed: incorrect seed size - given: %d wanted %d", len(seed), ed25519.SeedSize)
}
return pemEncodeEdPrivateKey(ed25519.NewKeyFromSeed(seed))
}
Expand All @@ -36,7 +36,7 @@ func Ed25519DerivePublicKey(privatekey []byte) ([]byte, error) {
}
b, err := x509.MarshalPKIXPublicKey(secret.Public())
if err != nil {
return nil, fmt.Errorf("MarshalPKIXPublicKey: failed to marshal PKIX public key: %w", err)
return nil, fmt.Errorf("marshalPKIXPublicKey: failed to marshal PKIX public key: %w", err)
}
return pem.EncodeToMemory(&pem.Block{
Type: "PUBLIC KEY",
Expand All @@ -48,7 +48,7 @@ func Ed25519DerivePublicKey(privatekey []byte) ([]byte, error) {
func pemEncodeEdPrivateKey(secret ed25519.PrivateKey) ([]byte, error) {
der, err := x509.MarshalPKCS8PrivateKey(secret)
if err != nil {
return nil, fmt.Errorf("MarshalPKCS8PrivateKey: failed to marshal ed25519 private key: %w", err)
return nil, fmt.Errorf("marshalPKCS8PrivateKey: failed to marshal ed25519 private key: %w", err)
}
block := &pem.Block{
Type: "PRIVATE KEY",
Expand All @@ -57,7 +57,7 @@ func pemEncodeEdPrivateKey(secret ed25519.PrivateKey) ([]byte, error) {
buf := &bytes.Buffer{}
err = pem.Encode(buf, block)
if err != nil {
return nil, fmt.Errorf("Encode: failed to encode generated ed25519 private key: PEM encoding failed: %w", err)
return nil, fmt.Errorf("encode: PEM encoding: %w", err)
}
return buf.Bytes(), nil
}
Expand All @@ -67,11 +67,11 @@ func pemEncodeEdPrivateKey(secret ed25519.PrivateKey) ([]byte, error) {
func ed25519DecodeFromPEM(privatekey []byte) (ed25519.PrivateKey, error) {
block, _ := pem.Decode(privatekey)
if block == nil {
return nil, fmt.Errorf("Decode: failed to read key")
return nil, fmt.Errorf("decode: failed to read key")
}
priv, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("ParsePKCS8PrivateKey: invalid private key: %w", err)
return nil, fmt.Errorf("parsePKCS8PrivateKey: invalid private key: %w", err)
}
secret, ok := priv.(ed25519.PrivateKey)
if !ok {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions docs-src/content/functions/crypto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ funcs:
-----END PUBLIC KEY-----
- name: crypto.Ed25519GenerateKey
experimental: true
released: v3.11.5
released: v4.0.0
description: |
Generate a new Ed25519 Private Key and output in
PEM-encoded PKCS#8 ASN.1 DER form.
Expand All @@ -172,7 +172,7 @@ funcs:
...
- name: crypto.Ed25519GenerateKeyFromSeed
experimental: true
released: v3.11.5
released: v4.0.0
description: |
Generate a new Ed25519 Private Key from a random seed and output in
PEM-encoded PKCS#8 ASN.1 DER form.
Expand All @@ -191,7 +191,7 @@ funcs:
...
- name: crypto.Ed25519DerivePublicKey
experimental: true
released: v3.11.5
released: v4.0.0
description: |
Derive a public key from an Ed25519 private key and output in PKIX
ASN.1 DER form.
Expand Down

0 comments on commit a27b507

Please sign in to comment.