Skip to content

Commit 46504e4

Browse files
authored
🤖 Merge PR DefinitelyTyped#72508 feat(node/tls): add TLSSocket.setKeyCert() by @hkleungai
1 parent 0246784 commit 46504e4

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

‎types/node/test/tls.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ import {
7171

7272
tlsSocket.getPeerX509Certificate(); // $ExpectType X509Certificate | undefined
7373
tlsSocket.getX509Certificate(); // $ExpectType X509Certificate | undefined
74+
75+
tlsSocket.setKeyCert({
76+
cert: fs.readFileSync("cert_filepath"),
77+
key: fs.readFileSync("key_filepath"),
78+
});
79+
tlsSocket.setKeyCert(createSecureContext({
80+
key: "NOT REALLY A KEY",
81+
cert: "SOME CERTIFICATE",
82+
}));
7483
}
7584

7685
{

‎types/node/tls.d.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ declare module "tls" {
398398
},
399399
callback: (err: Error | null) => void,
400400
): undefined | boolean;
401+
/**
402+
* The `tlsSocket.setKeyCert()` method sets the private key and certificate to use for the socket.
403+
* This is mainly useful if you wish to select a server certificate from a TLS server's `ALPNCallback`.
404+
* @since v22.5.0, v20.17.0
405+
* @param context An object containing at least `key` and `cert` properties from the {@link createSecureContext()} `options`,
406+
* or a TLS context object created with {@link createSecureContext()} itself.
407+
*/
408+
setKeyCert(context: SecureContextOptions | SecureContext): void;
401409
/**
402410
* The `tlsSocket.setMaxSendFragment()` method sets the maximum TLS fragment size.
403411
* Returns `true` if setting the limit succeeded; `false` otherwise.

‎types/node/v20/test/tls.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ import {
6969

7070
tlsSocket.getPeerX509Certificate(); // $ExpectType X509Certificate | undefined
7171
tlsSocket.getX509Certificate(); // $ExpectType X509Certificate | undefined
72+
73+
tlsSocket.setKeyCert({
74+
cert: fs.readFileSync("cert_filepath"),
75+
key: fs.readFileSync("key_filepath"),
76+
});
77+
tlsSocket.setKeyCert(createSecureContext({
78+
key: "NOT REALLY A KEY",
79+
cert: "SOME CERTIFICATE",
80+
}));
7281
}
7382

7483
{

‎types/node/v20/tls.d.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ declare module "tls" {
398398
},
399399
callback: (err: Error | null) => void,
400400
): undefined | boolean;
401+
/**
402+
* The `tlsSocket.setKeyCert()` method sets the private key and certificate to use for the socket.
403+
* This is mainly useful if you wish to select a server certificate from a TLS server's `ALPNCallback`.
404+
* @since v22.5.0, v20.17.0
405+
* @param context An object containing at least `key` and `cert` properties from the {@link createSecureContext()} `options`,
406+
* or a TLS context object created with {@link createSecureContext()} itself.
407+
*/
408+
setKeyCert(context: SecureContextOptions | SecureContext): void;
401409
/**
402410
* The `tlsSocket.setMaxSendFragment()` method sets the maximum TLS fragment size.
403411
* Returns `true` if setting the limit succeeded; `false` otherwise.

0 commit comments

Comments
 (0)