Skip to content

Commit f524806

Browse files
Add DialContext and fix names
1 parent dbd65a8 commit f524806

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

pbtls.go renamed to kbtls.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package kbtls
33

44
import (
5+
"context"
56
"crypto"
67
"crypto/ed25519"
78
"crypto/rand"
@@ -252,6 +253,11 @@ func ClientTLSConfigForClientName(key ConnectionKey, clientName string) (*tls.Co
252253

253254
// Dial works like tls.Dial with a TLS config based on the provided connection key.
254255
func Dial(network string, address string, connectionKey string) (net.Conn, error) {
256+
return DialContext(context.Background(), network, address, connectionKey)
257+
}
258+
259+
// DialContext works like tls.Dial with a TLS config based on the provided connection key and a context.
260+
func DialContext(ctx context.Context, network string, address string, connectionKey string) (net.Conn, error) {
255261
key, err := ParseConnectionKey(connectionKey)
256262
if err != nil {
257263
return nil, fmt.Errorf("parse connection key: %w", err)
@@ -262,7 +268,9 @@ func Dial(network string, address string, connectionKey string) (net.Conn, error
262268
return nil, fmt.Errorf("generate client TLS config: %w", err)
263269
}
264270

265-
return tls.Dial(network, address, tlsConfig)
271+
dialer := tls.Dialer{Config: tlsConfig}
272+
273+
return dialer.DialContext(ctx, network, address)
266274
}
267275

268276
// Listen works like tls.Listen with a TLS config based on the provided connection key.

pbtls_test.go renamed to kbtls_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func TestClientServerConfigCompatibility(t *testing.T) {
116116
wait := make(chan struct{})
117117

118118
pipeA, pipeB := net.Pipe()
119-
defer pipeA.Close() //nolint:errcheck,gosec
120-
defer pipeB.Close() //nolint:errcheck,gosec
119+
defer pipeA.Close() //nolint:errcheck
120+
defer pipeB.Close() //nolint:errcheck
121121
defer func() {
122122
<-wait
123123
}()
@@ -178,8 +178,8 @@ func TestClientServerErrorIfKeyAndNameDiffers(t *testing.T) {
178178
wait := make(chan struct{})
179179

180180
pipeA, pipeB := net.Pipe()
181-
defer pipeA.Close() //nolint:errcheck,gosec
182-
defer pipeB.Close() //nolint:errcheck,gosec
181+
defer pipeA.Close() //nolint:errcheck
182+
defer pipeB.Close() //nolint:errcheck
183183
defer func() {
184184
<-wait
185185
}()
@@ -236,8 +236,8 @@ func TestClientServerErrorIfKeyDiffers(t *testing.T) {
236236
wait := make(chan struct{})
237237

238238
pipeA, pipeB := net.Pipe()
239-
defer pipeA.Close() //nolint:errcheck,gosec
240-
defer pipeB.Close() //nolint:errcheck,gosec
239+
defer pipeA.Close() //nolint:errcheck
240+
defer pipeB.Close() //nolint:errcheck
241241
defer func() {
242242
<-wait
243243
}()
@@ -308,7 +308,7 @@ func TestDialListen(t *testing.T) {
308308
return
309309
}
310310

311-
defer conn.Close() //nolint:errcheck,gosec
311+
defer conn.Close() //nolint:errcheck
312312

313313
_, err = conn.Write(testData)
314314
if err != nil {
@@ -321,7 +321,7 @@ func TestDialListen(t *testing.T) {
321321
t.Fatalf("accept: %v", err)
322322
}
323323

324-
defer conn.Close() //nolint:errcheck,gosec
324+
defer conn.Close() //nolint:errcheck
325325

326326
receivedData := make([]byte, len(testData))
327327

0 commit comments

Comments
 (0)