Skip to content

Commit 2d9249b

Browse files
authored
Replace deprecated elliptic.Marshal (#26800)
In PR #26786, the Go version for golangci-lint is bumped to 1.21. This causes the following error: ``` models/migrations/v1_16/v210.go:132:23: SA1019: elliptic.Marshal has been deprecated since Go 1.21: for ECDH, use the crypto/ecdh package. This function returns an encoding equivalent to that of PublicKey.Bytes in crypto/ecdh. (staticcheck) PublicKey: elliptic.Marshal(elliptic.P256(), parsed.PubKey.X, parsed.PubKey.Y), ``` The change now uses [func (*PublicKey) ECDH](https://pkg.go.dev/crypto/ecdsa#PublicKey.ECDH), which is added in Go 1.20.
1 parent 438c764 commit 2d9249b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

models/migrations/v1_16/v210.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package v1_16 //nolint
55

66
import (
7-
"crypto/elliptic"
87
"encoding/base32"
98
"fmt"
109
"strings"
@@ -123,13 +122,17 @@ func RemigrateU2FCredentials(x *xorm.Engine) error {
123122
if err != nil {
124123
continue
125124
}
125+
pubKey, err := parsed.PubKey.ECDH()
126+
if err != nil {
127+
continue
128+
}
126129
remigrated := &webauthnCredential{
127130
ID: reg.ID,
128131
Name: reg.Name,
129132
LowerName: strings.ToLower(reg.Name),
130133
UserID: reg.UserID,
131134
CredentialID: base32.HexEncoding.EncodeToString(parsed.KeyHandle),
132-
PublicKey: elliptic.Marshal(elliptic.P256(), parsed.PubKey.X, parsed.PubKey.Y),
135+
PublicKey: pubKey.Bytes(),
133136
AttestationType: "fido-u2f",
134137
AAGUID: []byte{},
135138
SignCount: reg.Counter,

0 commit comments

Comments
 (0)