Skip to content

Commit 1a7cb41

Browse files
yaronfcursoragent
andcommitted
fix: load P-256 WIMSE keys via ParseRawPrivateKey
Avoid deprecated ecdsa.PrivateKey.D assignment (SA1019 on Go 1.27). Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 6f4e295 commit 1a7cb41

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

wimse_conformance_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/base64"
88
"encoding/json"
99
"io"
10-
"math/big"
1110
"net/http"
1211
"os"
1312
"path/filepath"
@@ -136,12 +135,17 @@ func wimseEd25519Key(t *testing.T, jwk wimseJWK) (ed25519.PrivateKey, ed25519.Pu
136135
func wimseP256Key(t *testing.T, jwk wimseJWK) (*ecdsa.PrivateKey, ecdsa.PublicKey) {
137136
t.Helper()
138137
require.Equal(t, "ES256", jwk.Alg)
139-
priv := &ecdsa.PrivateKey{
140-
PublicKey: ecdsa.PublicKey{Curve: elliptic.P256()},
141-
D: new(big.Int).SetBytes(wimseB64u(t, jwk.D)),
142-
}
143-
priv.X = new(big.Int).SetBytes(wimseB64u(t, jwk.X))
144-
priv.Y = new(big.Int).SetBytes(wimseB64u(t, jwk.Y))
138+
curve := elliptic.P256()
139+
d := wimseB64u(t, jwk.D)
140+
orderLen := (curve.Params().N.BitLen() + 7) / 8
141+
require.LessOrEqual(t, len(d), orderLen)
142+
if len(d) < orderLen {
143+
padded := make([]byte, orderLen)
144+
copy(padded[orderLen-len(d):], d)
145+
d = padded
146+
}
147+
priv, err := ecdsa.ParseRawPrivateKey(curve, d)
148+
require.NoError(t, err)
145149
return priv, priv.PublicKey
146150
}
147151

0 commit comments

Comments
 (0)