Skip to content

Commit

Permalink
fix(client): keep Go 1.19 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz committed Mar 22, 2024
1 parent a1d913f commit 36c3412
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.20.x]
go-version: [1.19.x, 1.20.x]
name: Build with Go ${{ matrix.go-version }}
steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/questdb/go-questdb-client/v3

go 1.18
go 1.19

require (
github.com/stretchr/testify v1.9.0
Expand Down
21 changes: 5 additions & 16 deletions tcp_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"bufio"
"context"
"crypto"
"crypto/ecdh"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
Expand Down Expand Up @@ -67,21 +66,11 @@ func newTcpLineSender(ctx context.Context, conf *lineSenderConfig) (*tcpLineSend
if err != nil {
return nil, fmt.Errorf("failed to decode auth key: %v", err)
}
// elliptic.P256().ScalarBaseMult is deprecated, so we use ecdh key
// and convert it to the ecdsa one.
ecdhKey, err := ecdh.P256().NewPrivateKey(rawKey)
if err != nil {
return nil, fmt.Errorf("invalid auth key: %v", err)
}
ecdhPubKey := ecdhKey.PublicKey().Bytes()
key = &ecdsa.PrivateKey{
PublicKey: ecdsa.PublicKey{
Curve: elliptic.P256(),
X: big.NewInt(0).SetBytes(ecdhPubKey[1:33]),
Y: big.NewInt(0).SetBytes(ecdhPubKey[33:]),
},
D: big.NewInt(0).SetBytes(ecdhKey.Bytes()),
}
// TODO(puzpuzpuz): migrate to crypto/ecdh one we don't need to support Go 1.19
key = new(ecdsa.PrivateKey)
key.PublicKey.Curve = elliptic.P256()
key.PublicKey.X, key.PublicKey.Y = key.PublicKey.Curve.ScalarBaseMult(rawKey)
key.D = new(big.Int).SetBytes(rawKey)
}

if conf.tlsMode == tlsDisabled {
Expand Down

0 comments on commit 36c3412

Please sign in to comment.