nish 0.34.1 → 0.36.0
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/README.md +7 -6
- package/docs/AI.md +86 -16
- package/docs/INSTALL.md +22 -13
- package/llms.txt +5 -2
- package/package.json +15 -5
- package/runtime/async.d.mts +49 -0
- package/runtime/async.mjs +27 -0
- package/runtime/nish.d.ts +4681 -427
- package/runtime/nish.h +6 -2
- package/runtime/nish.mjs +4 -0
- package/runtime/runtime-net.c +22 -0
- package/runtime/runtime-shm.c +93 -2
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/README.md +131 -131
- package/std/base64.ts +34 -5
- package/std/bytes.ts +258 -42
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +297 -77
- package/std/net/http1-server.ts +430 -94
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +275 -101
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +801 -112
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +264 -52
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +1124 -201
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +430 -40
- package/std/sync/shm.ts +222 -15
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/net/tls/record.ts
CHANGED
|
@@ -147,13 +147,25 @@ const TLS_RECORD_FROM: i32 = 0
|
|
|
147
147
|
* `HKDF-Expand-Label(secret, "traffic upd", "", Hash.length)` over the hash
|
|
148
148
|
* `hashLength` names, held as a `Secret`. The old secret is the caller's to
|
|
149
149
|
* wipe.
|
|
150
|
+
*
|
|
151
|
+
* @param hashLength The hash length of the connection's suite, 32 or 48, and so how many bytes are derived.
|
|
152
|
+
* @param trafficSecret The direction's current traffic secret. This function does not wipe it.
|
|
153
|
+
* @returns A fresh `Secret` holding the next traffic secret, which the caller owns and wipes.
|
|
150
154
|
*/
|
|
151
155
|
export const tlsNextTrafficSecret = (hashLength: i32, trafficSecret: Secret<u8[]>): Secret<u8[]> => {
|
|
152
156
|
const none: u8[] = []
|
|
153
157
|
return tlsExpandLabel(hashLength, trafficSecret, "traffic upd", none, hashLength)
|
|
154
158
|
}
|
|
155
159
|
|
|
156
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* Whether `[off, off + len)` is a window inside an array of `length` elements: every caller's range check.
|
|
162
|
+
* It is written as `off <= length - len`, not `off + len <= length`, so a large `off` cannot overflow.
|
|
163
|
+
*
|
|
164
|
+
* @param length How many elements the array has.
|
|
165
|
+
* @param off Where the window starts.
|
|
166
|
+
* @param len How many elements the window spans.
|
|
167
|
+
* @returns `true` when `off` and `len` are not negative and the window ends at or before `length`.
|
|
168
|
+
*/
|
|
157
169
|
export const tlsRecordWindowFits = (length: i32, off: i32, len: i32): boolean =>
|
|
158
170
|
off >= 0 && len >= 0 && off <= length - len
|
|
159
171
|
|
|
@@ -175,6 +187,13 @@ const tlsWriteRecordHeader = (out: u8[], at: i32, type: i32, len: i32): void =>
|
|
|
175
187
|
* in, or the alert negated when the header announces a type this layer does
|
|
176
188
|
* not know (`unexpected_message`) or a body past 2^14 + 256 bytes
|
|
177
189
|
* (`record_overflow`, §5.2). The legacy version is not read (§5.1).
|
|
190
|
+
*
|
|
191
|
+
* @param buf The array that holds the bytes received so far.
|
|
192
|
+
* @param off Where in `buf` the record's header starts.
|
|
193
|
+
* @param avail How many bytes, from `off`, have arrived.
|
|
194
|
+
* @returns The whole record's length in bytes, header included; 0 while the header is not all in;
|
|
195
|
+
* `-TLS_ALERT_UNEXPECTED_MESSAGE` or `-TLS_ALERT_RECORD_OVERFLOW` for a header this layer refuses;
|
|
196
|
+
* `-TLS_ALERT_INTERNAL_ERROR` when `buf[off .. off + avail)` is not inside `buf`.
|
|
178
197
|
*/
|
|
179
198
|
export const tlsRecordLength = (buf: u8[], off: i32, avail: i32): i32 => {
|
|
180
199
|
if (!tlsRecordWindowFits(toI32(buf.length), off, avail)) {
|
|
@@ -211,14 +230,18 @@ export class TlsRecordReader {
|
|
|
211
230
|
/** The bytes held, or `empty` while the reader holds none. */
|
|
212
231
|
buffer: u8[]
|
|
213
232
|
/** The zero-length array `buffer` is while no buffer is borrowed. */
|
|
214
|
-
empty: u8[]
|
|
233
|
+
private empty: u8[]
|
|
215
234
|
/** Where `buffer` comes from and goes back to. */
|
|
216
|
-
pool: BufferPool
|
|
235
|
+
private pool: BufferPool
|
|
217
236
|
/** The first byte not yet consumed. */
|
|
218
237
|
start: i32 = 0
|
|
219
238
|
/** One past the last byte pushed. */
|
|
220
239
|
end: i32 = 0
|
|
221
240
|
|
|
241
|
+
/**
|
|
242
|
+
* Makes an empty reader with a pool of its own, one buffer deep. No buffer is
|
|
243
|
+
* taken until the first `push` brings a byte.
|
|
244
|
+
*/
|
|
222
245
|
constructor() {
|
|
223
246
|
this.empty = []
|
|
224
247
|
this.buffer = this.empty
|
|
@@ -228,6 +251,8 @@ export class TlsRecordReader {
|
|
|
228
251
|
/**
|
|
229
252
|
* Borrows from `pool` from now on, giving back first, zeroed, any buffer
|
|
230
253
|
* held from the old one. Every byte held is forgotten, as `reset` does.
|
|
254
|
+
*
|
|
255
|
+
* @internal Read by `net/tls/record-server.ts`.
|
|
231
256
|
*/
|
|
232
257
|
borrowFrom(pool: BufferPool): void {
|
|
233
258
|
this.reset()
|
|
@@ -242,7 +267,7 @@ export class TlsRecordReader {
|
|
|
242
267
|
}
|
|
243
268
|
|
|
244
269
|
/** Gives the buffer back, zeroed, if one is held. */
|
|
245
|
-
giveBack(): void {
|
|
270
|
+
private giveBack(): void {
|
|
246
271
|
if (this.buffer.length > 0) {
|
|
247
272
|
// Every byte of it may have held a record: zero all of it.
|
|
248
273
|
this.pool.giveSecret(this.buffer, TLS_MAX_RECORD)
|
|
@@ -250,7 +275,11 @@ export class TlsRecordReader {
|
|
|
250
275
|
}
|
|
251
276
|
}
|
|
252
277
|
|
|
253
|
-
/**
|
|
278
|
+
/**
|
|
279
|
+
* How many bytes `push` would take now.
|
|
280
|
+
*
|
|
281
|
+
* @returns `TLS_MAX_RECORD` less the bytes held and not yet consumed.
|
|
282
|
+
*/
|
|
254
283
|
space(): i32 {
|
|
255
284
|
return TLS_MAX_RECORD - (this.end - this.start)
|
|
256
285
|
}
|
|
@@ -259,6 +288,12 @@ export class TlsRecordReader {
|
|
|
259
288
|
* Copies as many of `data[off .. off + len)` as fit and answers how many,
|
|
260
289
|
* after moving what is held to the front. A window outside `data` is
|
|
261
290
|
* `-TLS_ALERT_INTERNAL_ERROR`, and nothing is copied.
|
|
291
|
+
*
|
|
292
|
+
* @param data The array that holds the bytes read from the stream.
|
|
293
|
+
* @param off Where in `data` the new bytes start.
|
|
294
|
+
* @param len How many bytes, from `off`, to offer.
|
|
295
|
+
* @returns How many of the bytes were taken, from 0 (the buffer is full) up to `len`; the caller offers the
|
|
296
|
+
* rest again once a record is consumed. `-TLS_ALERT_INTERNAL_ERROR` for a window outside `data`.
|
|
262
297
|
*/
|
|
263
298
|
push(data: u8[], off: i32, len: i32): i32 {
|
|
264
299
|
if (!tlsRecordWindowFits(toI32(data.length), off, len)) {
|
|
@@ -292,6 +327,9 @@ export class TlsRecordReader {
|
|
|
292
327
|
* The length of the whole record at `start`, header included, once every
|
|
293
328
|
* byte of it is in; 0 before; or the alert negated for a header this layer
|
|
294
329
|
* refuses, as `tlsRecordLength` says.
|
|
330
|
+
*
|
|
331
|
+
* @returns The record's length in bytes, read at `buffer[start]`; 0 while it is not all in; or a negative
|
|
332
|
+
* `TLS_ALERT_*` value, the alert to send.
|
|
295
333
|
*/
|
|
296
334
|
next(): i32 {
|
|
297
335
|
const avail: i32 = this.end - this.start
|
|
@@ -303,6 +341,8 @@ export class TlsRecordReader {
|
|
|
303
341
|
* Lets the first `n` held bytes go: the record `next` answered, once it is
|
|
304
342
|
* handled. When none are left the next record starts at the front; the
|
|
305
343
|
* buffer stays until `reset`.
|
|
344
|
+
*
|
|
345
|
+
* @param n How many bytes to let go, usually what `next` answered. Clamped to 0 and to the bytes held.
|
|
306
346
|
*/
|
|
307
347
|
consume(n: i32): void {
|
|
308
348
|
const held: i32 = this.end - this.start
|
|
@@ -345,7 +385,7 @@ export class TlsRecordProtection {
|
|
|
345
385
|
*/
|
|
346
386
|
recordLimit: i64 = 0
|
|
347
387
|
/** The negotiated suite, or 0 while the direction is cleartext. */
|
|
348
|
-
suite: i32 = 0
|
|
388
|
+
private suite: i32 = 0
|
|
349
389
|
/** The real content type of the last record `open` answered. */
|
|
350
390
|
contentType: i32 = 0
|
|
351
391
|
/** The arrays `key` and `aes` point into: AES-128's and ChaCha20's or AES-256's. */
|
|
@@ -356,8 +396,12 @@ export class TlsRecordProtection {
|
|
|
356
396
|
/** Where `advance` derives the next traffic secret: HashLen bytes of it. */
|
|
357
397
|
next: u8[]
|
|
358
398
|
/** Where the keys are derived. */
|
|
359
|
-
kdf: HkdfScratch
|
|
399
|
+
private kdf: HkdfScratch
|
|
360
400
|
|
|
401
|
+
/**
|
|
402
|
+
* Makes a cleartext direction and every array it will fill, so that no
|
|
403
|
+
* install allocates. The record limit starts at `TLS_KEY_UPDATE_RECORDS`.
|
|
404
|
+
*/
|
|
361
405
|
constructor() {
|
|
362
406
|
this.key16 = new Array<u8>(16)
|
|
363
407
|
this.key32 = new Array<u8>(32)
|
|
@@ -370,7 +414,11 @@ export class TlsRecordProtection {
|
|
|
370
414
|
this.recordLimit = TLS_KEY_UPDATE_RECORDS
|
|
371
415
|
}
|
|
372
416
|
|
|
373
|
-
/**
|
|
417
|
+
/**
|
|
418
|
+
* Whether records in this direction are protected.
|
|
419
|
+
*
|
|
420
|
+
* @returns `true` once a suite is installed; `false` while the direction is cleartext.
|
|
421
|
+
*/
|
|
374
422
|
isProtected(): boolean {
|
|
375
423
|
return this.suite !== 0
|
|
376
424
|
}
|
|
@@ -380,6 +428,8 @@ export class TlsRecordProtection {
|
|
|
380
428
|
* and both AES key schedules wiped: the keys and IV with `secureZero`, and
|
|
381
429
|
* each schedule with `aesKeyWipe`, its whole `roundKeys` and its H, which
|
|
382
430
|
* the next `install` fills again (TLS-2).
|
|
431
|
+
*
|
|
432
|
+
* @internal Read by `net/tls/record-server.ts` and `net/tls/record-client.ts`.
|
|
383
433
|
*/
|
|
384
434
|
clear(): void {
|
|
385
435
|
secureZero(this.key16)
|
|
@@ -402,6 +452,11 @@ export class TlsRecordProtection {
|
|
|
402
452
|
* The key, the IV and the AES key schedule are written into the arrays this
|
|
403
453
|
* direction made when it was constructed, so an install allocates nothing
|
|
404
454
|
* that outlives it (TLS-3).
|
|
455
|
+
*
|
|
456
|
+
* @param suite The negotiated cipher suite, such as `TLS_AES_128_GCM_SHA256`.
|
|
457
|
+
* @param secret The direction's traffic secret, plain. It is read, not kept, and stays the caller's to
|
|
458
|
+
* wipe.
|
|
459
|
+
* @returns `true` when the direction is now protected; `false` when it was left cleartext.
|
|
405
460
|
*/
|
|
406
461
|
install(suite: i32, secret: u8[]): boolean {
|
|
407
462
|
this.clear()
|
|
@@ -416,7 +471,7 @@ export class TlsRecordProtection {
|
|
|
416
471
|
}
|
|
417
472
|
|
|
418
473
|
/** Points `key`, and for AES `aes`, at the arrays of the size `suite` needs. */
|
|
419
|
-
reserve(suite: i32): void {
|
|
474
|
+
private reserve(suite: i32): void {
|
|
420
475
|
this.key = tlsSuiteKeyLength(suite) === 16 ? this.key16 : this.key32
|
|
421
476
|
if (suite !== TLS_CHACHA20_POLY1305_SHA256) {
|
|
422
477
|
this.aes = tlsSuiteKeyLength(suite) === 16 ? this.aes128 : this.aes256
|
|
@@ -431,7 +486,7 @@ export class TlsRecordProtection {
|
|
|
431
486
|
* inside an arena block, so a key install leaves the arena where it was.
|
|
432
487
|
* ChaCha20 has no schedule.
|
|
433
488
|
*/
|
|
434
|
-
derive(suite: i32, secret: u8[]): void {
|
|
489
|
+
private derive(suite: i32, secret: u8[]): void {
|
|
435
490
|
using _scope = arena()
|
|
436
491
|
tlsTrafficKeysInto(this.kdf, suite, secret, this.key, this.iv)
|
|
437
492
|
const aes: AesKey | null = this.aes
|
|
@@ -445,7 +500,7 @@ export class TlsRecordProtection {
|
|
|
445
500
|
* ChaCha20: a protection that carried AES keeps its schedule for the next
|
|
446
501
|
* AES key, and must not use it for ChaCha20.
|
|
447
502
|
*/
|
|
448
|
-
aesForSuite(): AesKey | null {
|
|
503
|
+
private aesForSuite(): AesKey | null {
|
|
449
504
|
return this.suite === TLS_CHACHA20_POLY1305_SHA256 ? null : this.aes
|
|
450
505
|
}
|
|
451
506
|
|
|
@@ -455,6 +510,11 @@ export class TlsRecordProtection {
|
|
|
455
510
|
* and the keys are installed from it; the next secret's own copy is wiped.
|
|
456
511
|
* The next secret is derived in place inside an arena block, as `derive`'s
|
|
457
512
|
* keys are. False, as `install` answers, when the keys do not install.
|
|
513
|
+
*
|
|
514
|
+
* @param secret The direction's current traffic secret, plain, which is overwritten with the next one. It
|
|
515
|
+
* stays the caller's to wipe. One shorter than the suite's hash length panics in HKDF.
|
|
516
|
+
* @returns `true` when the next keys are installed; `false` for a cleartext direction, or when the install
|
|
517
|
+
* fails and the direction is left cleartext.
|
|
458
518
|
*/
|
|
459
519
|
advance(secret: u8[]): boolean {
|
|
460
520
|
const suite: i32 = this.suite
|
|
@@ -492,6 +552,10 @@ export class TlsRecordProtection {
|
|
|
492
552
|
* plain output of each derivation wiped, and the AES key schedule expanded
|
|
493
553
|
* into place inside an arena block, as `derive`'s is. `false`, leaving the
|
|
494
554
|
* direction cleartext, where `install` answers it.
|
|
555
|
+
*
|
|
556
|
+
* @param suite The negotiated cipher suite, such as `TLS_AES_128_GCM_SHA256`.
|
|
557
|
+
* @param secret The direction's held traffic secret. It is read, not kept, and stays the caller's to wipe.
|
|
558
|
+
* @returns `true` when the direction is now protected; `false` when it was left cleartext.
|
|
495
559
|
*/
|
|
496
560
|
installHeld(suite: i32, secret: Secret<u8[]>): boolean {
|
|
497
561
|
this.clear()
|
|
@@ -516,6 +580,11 @@ export class TlsRecordProtection {
|
|
|
516
580
|
* ratchet that leaves no copy of either, and the keys are installed from
|
|
517
581
|
* it with `installHeld`. False, as `advance` answers, when the keys do not
|
|
518
582
|
* install; a secret that is not its hash's length is left as it was.
|
|
583
|
+
*
|
|
584
|
+
* @param secret The direction's held traffic secret, overwritten in place with the next one. It stays the
|
|
585
|
+
* caller's to wipe.
|
|
586
|
+
* @returns `true` when the next keys are installed; `false` for a cleartext direction, or when the install
|
|
587
|
+
* fails and the direction is left cleartext.
|
|
519
588
|
*/
|
|
520
589
|
advanceHeld(secret: Secret<u8[]>): boolean {
|
|
521
590
|
const suite: i32 = this.suite
|
|
@@ -534,7 +603,13 @@ export class TlsRecordProtection {
|
|
|
534
603
|
return this.installHeld(suite, secret)
|
|
535
604
|
}
|
|
536
605
|
|
|
537
|
-
/**
|
|
606
|
+
/**
|
|
607
|
+
* The per-record nonce (§5.3): the IV with the sequence number XORed into its last eight bytes,
|
|
608
|
+
* big-endian.
|
|
609
|
+
*
|
|
610
|
+
* @param nonce Where the nonce is written, from index 0: 12 bytes, or as many as fit. It is as secret as
|
|
611
|
+
* the IV, so the caller wipes it after use, as `seal` and `open` do.
|
|
612
|
+
*/
|
|
538
613
|
nonceInto(nonce: u8[]): void {
|
|
539
614
|
for (let k: i32 = 0; k < TLS_IV_SIZE && k < toI32(nonce.length) && k < toI32(this.iv.length); k++) {
|
|
540
615
|
const shift: i32 = (TLS_IV_SIZE - 1 - k) << 3
|
|
@@ -553,6 +628,16 @@ export class TlsRecordProtection {
|
|
|
553
628
|
* with nothing written, for content over 2^14 bytes, a padding that would
|
|
554
629
|
* take the inner plaintext past 2^14 + 1, a window outside `data`, too
|
|
555
630
|
* little room at `out[at]`, or a sequence number that would wrap.
|
|
631
|
+
*
|
|
632
|
+
* @param type The content type to send, such as `TLS_CONTENT_HANDSHAKE`.
|
|
633
|
+
* @param data The array that holds the content.
|
|
634
|
+
* @param off Where in `data` the content starts.
|
|
635
|
+
* @param len How many bytes of content, from `off`, to seal: at most 2^14.
|
|
636
|
+
* @param padding How many zero bytes to add inside the protected record; 0 when cleartext.
|
|
637
|
+
* @param out Where the record is written.
|
|
638
|
+
* @param at Where in `out` the record's header starts.
|
|
639
|
+
* @returns The record's length in bytes, header included (and the tag, when protected), or
|
|
640
|
+
* `-TLS_ALERT_INTERNAL_ERROR`.
|
|
556
641
|
*/
|
|
557
642
|
seal(type: i32, data: u8[], off: i32, len: i32, padding: i32, out: u8[], at: i32): i32 {
|
|
558
643
|
if (!tlsRecordWindowFits(toI32(data.length), off, len) || len > TLS_MAX_PLAINTEXT || padding < 0) {
|
|
@@ -623,6 +708,18 @@ export class TlsRecordProtection {
|
|
|
623
708
|
* that is all zeros is `unexpected_message` (§5.4). Every refusal is the
|
|
624
709
|
* alert negated; a window outside `record`, a `len` that is not the
|
|
625
710
|
* header's, or too little room at `out[at]` is `-TLS_ALERT_INTERNAL_ERROR`.
|
|
711
|
+
*
|
|
712
|
+
* A protected record that fails to authenticate leaves the sequence number
|
|
713
|
+
* where it was; one that authenticates spends its number even when its
|
|
714
|
+
* content is then refused.
|
|
715
|
+
*
|
|
716
|
+
* @param record The array that holds the record, usually a reader's buffer.
|
|
717
|
+
* @param off Where in `record` the record's header starts.
|
|
718
|
+
* @param len The whole record's length in bytes, header included, as `tlsRecordLength` answered it.
|
|
719
|
+
* @param out Where the content is written.
|
|
720
|
+
* @param at Where in `out` the content starts.
|
|
721
|
+
* @returns The content's length in bytes, which may be 0, or a negative `TLS_ALERT_*` value, the alert to
|
|
722
|
+
* send.
|
|
626
723
|
*/
|
|
627
724
|
open(record: u8[], off: i32, len: i32, out: u8[], at: i32): i32 {
|
|
628
725
|
if (!tlsRecordWindowFits(toI32(record.length), off, len) || len < TLS_RECORD_HEADER_SIZE) {
|