Skip to content

Commit 900e4f3

Browse files
authored
Merge pull request #80 from sorcererxw/main
Fix dbutil generated key type
2 parents b3c5f6e + 2646911 commit 900e4f3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

planetscale/dbutil/dbutil.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ type DialConfig struct {
4141
}
4242

4343
func generateKey() (crypto.PrivateKey, error) {
44-
pkey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
45-
if err != nil {
46-
return nil, err
47-
}
48-
return &pkey, nil
44+
return ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
4945
}
5046

5147
// Dial creates a secure connection to a PlanetScale database with the given

planetscale/dbutil/dbutil_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dbutil
22

33
import (
44
"context"
5+
"crypto/ecdsa"
56
"crypto/tls"
67
"crypto/x509"
78
"encoding/pem"
@@ -172,3 +173,16 @@ func parseCert(pemCert string) (*x509.Certificate, error) {
172173
}
173174
return x509.ParseCertificate(bl.Bytes)
174175
}
176+
177+
func TestGenerateKey(t *testing.T) {
178+
key, err := generateKey()
179+
if err != nil {
180+
t.Fatal(err)
181+
}
182+
183+
_, ok := key.(*ecdsa.PrivateKey)
184+
185+
if !ok {
186+
t.Fatal("generated key is not an ECDSA private key")
187+
}
188+
}

0 commit comments

Comments
 (0)