@floegence/flowersec-core 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/e2ee/handshake.d.ts +2 -2
- package/dist/e2ee/handshake.js +12 -3
- package/package.json +1 -1
package/dist/e2ee/handshake.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type HandshakeClientOptions = Readonly<{
|
|
|
18
18
|
maxBufferedBytes?: number;
|
|
19
19
|
/** Optional AbortSignal to cancel the handshake. */
|
|
20
20
|
signal?: AbortSignal;
|
|
21
|
-
/** Optional total handshake timeout in milliseconds (0 disables). */
|
|
21
|
+
/** Optional total handshake timeout in milliseconds (>= 0; 0 disables). */
|
|
22
22
|
timeoutMs?: number;
|
|
23
23
|
}>;
|
|
24
24
|
export type HandshakeServerOptions = Readonly<{
|
|
@@ -42,7 +42,7 @@ export type HandshakeServerOptions = Readonly<{
|
|
|
42
42
|
maxBufferedBytes?: number;
|
|
43
43
|
/** Optional AbortSignal to cancel the handshake. */
|
|
44
44
|
signal?: AbortSignal;
|
|
45
|
-
/** Optional total handshake timeout in milliseconds (0 disables). */
|
|
45
|
+
/** Optional total handshake timeout in milliseconds (>= 0; 0 disables). */
|
|
46
46
|
timeoutMs?: number;
|
|
47
47
|
}>;
|
|
48
48
|
export declare function clientHandshake(transport: BinaryTransport, opts: HandshakeClientOptions): Promise<SecureChannel>;
|
package/dist/e2ee/handshake.js
CHANGED
|
@@ -13,7 +13,9 @@ import { TimeoutError, throwIfAborted } from "../utils/errors.js";
|
|
|
13
13
|
const te = new TextEncoder();
|
|
14
14
|
const td = new TextDecoder();
|
|
15
15
|
function handshakeDeadlineMs(timeoutMs) {
|
|
16
|
-
const ms =
|
|
16
|
+
const ms = timeoutMs ?? 10_000;
|
|
17
|
+
if (!Number.isFinite(ms) || ms < 0)
|
|
18
|
+
throw new Error("timeoutMs must be >= 0");
|
|
17
19
|
if (ms <= 0)
|
|
18
20
|
return null;
|
|
19
21
|
return Date.now() + ms;
|
|
@@ -172,8 +174,15 @@ export class ServerHandshakeCache {
|
|
|
172
174
|
// Maximum number of cached entries.
|
|
173
175
|
maxEntries;
|
|
174
176
|
constructor(opts = {}) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
const ttlMs = opts.ttlMs ?? 60_000;
|
|
178
|
+
if (!Number.isFinite(ttlMs) || ttlMs < 0)
|
|
179
|
+
throw new Error("ttlMs must be >= 0");
|
|
180
|
+
const maxEntries = opts.maxEntries ?? 4096;
|
|
181
|
+
if (!Number.isFinite(maxEntries) || maxEntries < 0 || !Number.isInteger(maxEntries)) {
|
|
182
|
+
throw new Error("maxEntries must be an integer >= 0");
|
|
183
|
+
}
|
|
184
|
+
this.ttlMs = ttlMs;
|
|
185
|
+
this.maxEntries = maxEntries;
|
|
177
186
|
}
|
|
178
187
|
cleanup(nowMs) {
|
|
179
188
|
if (this.ttlMs <= 0)
|