@cratestack/ts-types 0.18.0 → 0.18.1
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/cbor-argument.d.ts +25 -0
- package/dist/cbor-argument.d.ts.map +1 -0
- package/dist/cbor-argument.js +62 -0
- package/dist/cbor-argument.js.map +1 -0
- package/dist/cbor-item.d.ts +3 -24
- package/dist/cbor-item.d.ts.map +1 -1
- package/dist/cbor-item.js +42 -84
- package/dist/cbor-item.js.map +1 -1
- package/dist/cbor-seq.d.ts +1 -1
- package/dist/cbor-seq.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** A cbor-seq body the walker can't make sense of at all — a reserved
|
|
2
|
+
* additional-info value, an indefinite-length string chunk of the
|
|
3
|
+
* wrong major type, a stray "break" byte with nothing open, etc. This
|
|
4
|
+
* is always a hard failure: unlike running out of bytes mid-item, more
|
|
5
|
+
* data arriving later can never fix it. */
|
|
6
|
+
export declare class MalformedCborSeqError extends Error {
|
|
7
|
+
}
|
|
8
|
+
/** Not enough bytes yet to know where the current item ends. Callers
|
|
9
|
+
* (`CborSeqBoundaryScanner.feedChunk`) catch this and just wait for
|
|
10
|
+
* the next chunk — it is never a real failure. */
|
|
11
|
+
export declare class NeedMoreBytesError extends Error {
|
|
12
|
+
}
|
|
13
|
+
export declare function skipArgument(bytes: Uint8Array, cursor: number, info: number): number;
|
|
14
|
+
/** Read the argument (length/count/tag-number/value) encoded by
|
|
15
|
+
* `additionalInfo` starting at `offset`. `additionalInfo <= 23` means
|
|
16
|
+
* it's inline in the initial byte already consumed by the caller; 24,
|
|
17
|
+
* 25, 26, 27 mean 1, 2, 4, 8 big-endian bytes follow respectively.
|
|
18
|
+
* Exported so `./cbor-seq`'s tag-header detection can reuse the exact
|
|
19
|
+
* same argument-decoding logic rather than a second copy of it. */
|
|
20
|
+
export declare function readArgument(bytes: Uint8Array, offset: number, additionalInfo: number): {
|
|
21
|
+
value: number;
|
|
22
|
+
next: number;
|
|
23
|
+
};
|
|
24
|
+
export declare function requireBytes(bytes: Uint8Array, endOffsetExclusive: number): number;
|
|
25
|
+
//# sourceMappingURL=cbor-argument.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cbor-argument.d.ts","sourceRoot":"","sources":["../src/cbor-argument.ts"],"names":[],"mappings":"AAAA;;;;4CAI4C;AAC5C,qBAAa,qBAAsB,SAAQ,KAAK;CAAG;AAEnD;;mDAEmD;AACnD,qBAAa,kBAAmB,SAAQ,KAAK;CAAG;AAEhD,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKpF;AAED;;;;;oEAKoE;AACpE,wBAAgB,YAAY,CAC1B,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACrB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA8BjC;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM,CAKlF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** A cbor-seq body the walker can't make sense of at all — a reserved
|
|
2
|
+
* additional-info value, an indefinite-length string chunk of the
|
|
3
|
+
* wrong major type, a stray "break" byte with nothing open, etc. This
|
|
4
|
+
* is always a hard failure: unlike running out of bytes mid-item, more
|
|
5
|
+
* data arriving later can never fix it. */
|
|
6
|
+
export class MalformedCborSeqError extends Error {
|
|
7
|
+
}
|
|
8
|
+
/** Not enough bytes yet to know where the current item ends. Callers
|
|
9
|
+
* (`CborSeqBoundaryScanner.feedChunk`) catch this and just wait for
|
|
10
|
+
* the next chunk — it is never a real failure. */
|
|
11
|
+
export class NeedMoreBytesError extends Error {
|
|
12
|
+
}
|
|
13
|
+
export function skipArgument(bytes, cursor, info) {
|
|
14
|
+
if (info <= 23)
|
|
15
|
+
return cursor;
|
|
16
|
+
const width = info === 24 ? 1 : info === 25 ? 2 : info === 26 ? 4 : info === 27 ? 8 : 0;
|
|
17
|
+
if (width === 0)
|
|
18
|
+
throw new MalformedCborSeqError(`reserved additional info ${info}`);
|
|
19
|
+
return requireBytes(bytes, cursor + width);
|
|
20
|
+
}
|
|
21
|
+
/** Read the argument (length/count/tag-number/value) encoded by
|
|
22
|
+
* `additionalInfo` starting at `offset`. `additionalInfo <= 23` means
|
|
23
|
+
* it's inline in the initial byte already consumed by the caller; 24,
|
|
24
|
+
* 25, 26, 27 mean 1, 2, 4, 8 big-endian bytes follow respectively.
|
|
25
|
+
* Exported so `./cbor-seq`'s tag-header detection can reuse the exact
|
|
26
|
+
* same argument-decoding logic rather than a second copy of it. */
|
|
27
|
+
export function readArgument(bytes, offset, additionalInfo) {
|
|
28
|
+
if (additionalInfo <= 23) {
|
|
29
|
+
return { value: additionalInfo, next: offset };
|
|
30
|
+
}
|
|
31
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
32
|
+
switch (additionalInfo) {
|
|
33
|
+
case 24:
|
|
34
|
+
requireBytes(bytes, offset + 1);
|
|
35
|
+
return { value: view.getUint8(offset), next: offset + 1 };
|
|
36
|
+
case 25:
|
|
37
|
+
requireBytes(bytes, offset + 2);
|
|
38
|
+
return { value: view.getUint16(offset, false), next: offset + 2 };
|
|
39
|
+
case 26:
|
|
40
|
+
requireBytes(bytes, offset + 4);
|
|
41
|
+
return { value: view.getUint32(offset, false), next: offset + 4 };
|
|
42
|
+
case 27: {
|
|
43
|
+
requireBytes(bytes, offset + 8);
|
|
44
|
+
const big = view.getBigUint64(offset, false);
|
|
45
|
+
if (big > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
46
|
+
throw new MalformedCborSeqError("cbor-seq item length/count exceeds what this scanner supports");
|
|
47
|
+
}
|
|
48
|
+
return { value: Number(big), next: offset + 8 };
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
// 28-30 are reserved; 31 (indefinite) is handled by the caller
|
|
52
|
+
// before `readArgument` is ever reached.
|
|
53
|
+
throw new MalformedCborSeqError(`reserved additional info ${additionalInfo}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function requireBytes(bytes, endOffsetExclusive) {
|
|
57
|
+
if (endOffsetExclusive > bytes.length) {
|
|
58
|
+
throw new NeedMoreBytesError();
|
|
59
|
+
}
|
|
60
|
+
return endOffsetExclusive;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=cbor-argument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cbor-argument.js","sourceRoot":"","sources":["../src/cbor-argument.ts"],"names":[],"mappings":"AAAA;;;;4CAI4C;AAC5C,MAAM,OAAO,qBAAsB,SAAQ,KAAK;CAAG;AAEnD;;mDAEmD;AACnD,MAAM,OAAO,kBAAmB,SAAQ,KAAK;CAAG;AAEhD,MAAM,UAAU,YAAY,CAAC,KAAiB,EAAE,MAAc,EAAE,IAAY;IAC1E,IAAI,IAAI,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC;IAC9B,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxF,IAAI,KAAK,KAAK,CAAC;QAAE,MAAM,IAAI,qBAAqB,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;IACrF,OAAO,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;oEAKoE;AACpE,MAAM,UAAU,YAAY,C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D,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;QAClD,CAAC;QACD;YACE,+DAA+D;YAC/D,yCAAyC;YACzC,MAAM,IAAI,qBAAqB,CAAC,4BAA4B,cAAc,EAAE,CAAC,CAAC;IAClF,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAiB,EAAE,kBAA0B;IACxE,IAAI,kBAAkB,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QACtC,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
|
package/dist/cbor-item.d.ts
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
* additional-info value, an indefinite-length string chunk of the
|
|
3
|
-
* wrong major type, a stray "break" byte with nothing open, etc. This
|
|
4
|
-
* is always a hard failure: unlike running out of bytes mid-item, more
|
|
5
|
-
* data arriving later can never fix it. */
|
|
6
|
-
export declare class MalformedCborSeqError extends Error {
|
|
7
|
-
}
|
|
8
|
-
/** Not enough bytes yet to know where the current item ends. Callers
|
|
9
|
-
* (`CborSeqBoundaryScanner.feedChunk`) catch this and just wait for
|
|
10
|
-
* the next chunk — it is never a real failure. */
|
|
11
|
-
export declare class NeedMoreBytesError extends Error {
|
|
12
|
-
}
|
|
1
|
+
export { MalformedCborSeqError, NeedMoreBytesError, readArgument } from "./cbor-argument.js";
|
|
13
2
|
/** Advance past exactly one top-level CBOR data item starting at
|
|
14
3
|
* `offset`, returning the offset just past it. Handles every major
|
|
15
4
|
* type, including indefinite-length byte strings, text strings,
|
|
16
5
|
* arrays, and maps (RFC 8949 §3.2.1-§3.2.3), recursively — the same
|
|
17
6
|
* structural cases `minicbor::Decoder::skip` covers on the Rust side.
|
|
18
|
-
*
|
|
19
|
-
export declare function skipItem(bytes: Uint8Array, offset: number): number;
|
|
20
|
-
/** Read the argument (length/count/tag-number/value) encoded by
|
|
21
|
-
* `additionalInfo` starting at `offset`. `additionalInfo <= 23` means
|
|
22
|
-
* it's inline in the initial byte already consumed by the caller; 24,
|
|
23
|
-
* 25, 26, 27 mean 1, 2, 4, 8 big-endian bytes follow respectively.
|
|
24
|
-
* Exported so `./cbor-seq`'s tag-header detection can reuse the exact
|
|
25
|
-
* same argument-decoding logic rather than a second copy of it. */
|
|
26
|
-
export declare function readArgument(bytes: Uint8Array, offset: number, additionalInfo: number): {
|
|
27
|
-
value: number;
|
|
28
|
-
next: number;
|
|
29
|
-
};
|
|
7
|
+
* It validates text and framing, but not tag semantics or map-key uniqueness. */
|
|
8
|
+
export declare function skipItem(bytes: Uint8Array, offset: number, depth?: number): number;
|
|
30
9
|
//# sourceMappingURL=cbor-item.d.ts.map
|
package/dist/cbor-item.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cbor-item.d.ts","sourceRoot":"","sources":["../src/cbor-item.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cbor-item.d.ts","sourceRoot":"","sources":["../src/cbor-item.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE7F;;;;;kFAKkF;AAClF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,CAmD7E"}
|
package/dist/cbor-item.js
CHANGED
|
@@ -1,37 +1,23 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// `crates/cratestack-client-rust/src/streaming.rs`'s use of
|
|
8
|
-
// `minicbor::Decoder::skip` deliberately, not reimplemented from a CBOR
|
|
9
|
-
// spec reading).
|
|
1
|
+
// Single-CBOR-item structural walker — the low-level half of the
|
|
2
|
+
// `application/cbor-seq` boundary scanner (issue #277, see
|
|
3
|
+
// `./cbor-seq` for the stateful, chunk-buffering half that consumes
|
|
4
|
+
// this). Walks structure, validates text UTF-8 and simple-value encoding,
|
|
5
|
+
// and bounds nesting to 256. It does not interpret tag semantics or enforce
|
|
6
|
+
// unique map keys; the server codec accepts duplicate keys.
|
|
10
7
|
//
|
|
11
|
-
// Internal to
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// does for the stateful half.
|
|
16
|
-
/** A cbor-seq body the walker can't make sense of at all — a reserved
|
|
17
|
-
* additional-info value, an indefinite-length string chunk of the
|
|
18
|
-
* wrong major type, a stray "break" byte with nothing open, etc. This
|
|
19
|
-
* is always a hard failure: unlike running out of bytes mid-item, more
|
|
20
|
-
* data arriving later can never fix it. */
|
|
21
|
-
export class MalformedCborSeqError extends Error {
|
|
22
|
-
}
|
|
23
|
-
/** Not enough bytes yet to know where the current item ends. Callers
|
|
24
|
-
* (`CborSeqBoundaryScanner.feedChunk`) catch this and just wait for
|
|
25
|
-
* the next chunk — it is never a real failure. */
|
|
26
|
-
export class NeedMoreBytesError extends Error {
|
|
27
|
-
}
|
|
8
|
+
// Internal to the generated package (not re-exported from `./index`) —
|
|
9
|
+
// `./cbor-seq` is the public surface for boundary-scanning.
|
|
10
|
+
import { MalformedCborSeqError, NeedMoreBytesError, readArgument, requireBytes, skipArgument, } from "./cbor-argument.js";
|
|
11
|
+
export { MalformedCborSeqError, NeedMoreBytesError, readArgument } from "./cbor-argument.js";
|
|
28
12
|
/** Advance past exactly one top-level CBOR data item starting at
|
|
29
13
|
* `offset`, returning the offset just past it. Handles every major
|
|
30
14
|
* type, including indefinite-length byte strings, text strings,
|
|
31
15
|
* arrays, and maps (RFC 8949 §3.2.1-§3.2.3), recursively — the same
|
|
32
16
|
* structural cases `minicbor::Decoder::skip` covers on the Rust side.
|
|
33
|
-
*
|
|
34
|
-
export function skipItem(bytes, offset) {
|
|
17
|
+
* It validates text and framing, but not tag semantics or map-key uniqueness. */
|
|
18
|
+
export function skipItem(bytes, offset, depth = 0) {
|
|
19
|
+
if (depth > 256)
|
|
20
|
+
throw new MalformedCborSeqError("CBOR nesting limit exceeded");
|
|
35
21
|
if (offset >= bytes.length) {
|
|
36
22
|
throw new NeedMoreBytesError();
|
|
37
23
|
}
|
|
@@ -48,31 +34,41 @@ export function skipItem(bytes, offset) {
|
|
|
48
34
|
if (majorType === 0 || majorType === 1 || majorType === 6) {
|
|
49
35
|
throw new MalformedCborSeqError(`major type ${majorType} cannot use indefinite-length encoding`);
|
|
50
36
|
}
|
|
51
|
-
return skipIndefinite(bytes, cursor, majorType);
|
|
37
|
+
return skipIndefinite(bytes, cursor, majorType, depth);
|
|
38
|
+
}
|
|
39
|
+
// Scalar values and tags can span all 64 bits: only lengths need a JS number.
|
|
40
|
+
if (majorType === 0 || majorType === 1 || majorType === 6) {
|
|
41
|
+
const next = skipArgument(bytes, cursor, additionalInfo);
|
|
42
|
+
return majorType === 6 ? skipItem(bytes, next, depth + 1) : next;
|
|
52
43
|
}
|
|
53
44
|
const argument = readArgument(bytes, cursor, additionalInfo);
|
|
54
45
|
switch (majorType) {
|
|
55
|
-
case 0: // unsigned integer — the argument IS the value, no payload
|
|
56
|
-
case 1: // negative integer
|
|
57
|
-
return argument.next;
|
|
58
46
|
case 2: // byte string
|
|
59
|
-
case 3: // text string
|
|
60
47
|
return requireBytes(bytes, argument.next + argument.value);
|
|
48
|
+
case 3: {
|
|
49
|
+
// each definite text chunk must be valid UTF-8
|
|
50
|
+
const end = requireBytes(bytes, argument.next + argument.value);
|
|
51
|
+
try {
|
|
52
|
+
new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(argument.next, end));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
throw new MalformedCborSeqError("invalid CBOR text UTF-8");
|
|
56
|
+
}
|
|
57
|
+
return end;
|
|
58
|
+
}
|
|
61
59
|
case 4: // array — `argument.value` items follow
|
|
62
|
-
return skipCount(bytes, argument.next, argument.value, 1);
|
|
60
|
+
return skipCount(bytes, argument.next, argument.value, 1, depth);
|
|
63
61
|
case 5: // map — `argument.value` key/value pairs follow
|
|
64
|
-
return skipCount(bytes, argument.next, argument.value, 2);
|
|
65
|
-
case 6: // tag — exactly one nested item follows the tag number
|
|
66
|
-
return skipItem(bytes, argument.next);
|
|
62
|
+
return skipCount(bytes, argument.next, argument.value, 2, depth);
|
|
67
63
|
default:
|
|
68
64
|
// Unreachable: majorType is `initial >> 5`, always 0-7.
|
|
69
65
|
throw new MalformedCborSeqError(`unreachable CBOR major type ${majorType}`);
|
|
70
66
|
}
|
|
71
67
|
}
|
|
72
|
-
function skipCount(bytes, start, count, itemsPerElement) {
|
|
68
|
+
function skipCount(bytes, start, count, itemsPerElement, depth) {
|
|
73
69
|
let cursor = start;
|
|
74
70
|
for (let i = 0; i < count * itemsPerElement; i++) {
|
|
75
|
-
cursor = skipItem(bytes, cursor);
|
|
71
|
+
cursor = skipItem(bytes, cursor, depth + 1);
|
|
76
72
|
}
|
|
77
73
|
return cursor;
|
|
78
74
|
}
|
|
@@ -82,7 +78,10 @@ function skipSimpleOrFloat(bytes, cursor, additionalInfo) {
|
|
|
82
78
|
}
|
|
83
79
|
switch (additionalInfo) {
|
|
84
80
|
case 24:
|
|
85
|
-
|
|
81
|
+
requireBytes(bytes, cursor + 1);
|
|
82
|
+
if (bytes[cursor] < 32)
|
|
83
|
+
throw new MalformedCborSeqError("invalid CBOR simple value");
|
|
84
|
+
return cursor + 1;
|
|
86
85
|
case 25:
|
|
87
86
|
return requireBytes(bytes, cursor + 2); // half-precision float
|
|
88
87
|
case 26:
|
|
@@ -100,7 +99,7 @@ function skipSimpleOrFloat(bytes, cursor, additionalInfo) {
|
|
|
100
99
|
* byte (`0xff`). Byte/text strings additionally require every chunk to
|
|
101
100
|
* be a definite-length chunk of the *same* major type (RFC 8949
|
|
102
101
|
* §3.2.3) — nesting or mixing major types there is malformed. */
|
|
103
|
-
function skipIndefinite(bytes, start, majorType) {
|
|
102
|
+
function skipIndefinite(bytes, start, majorType, depth) {
|
|
104
103
|
let cursor = start;
|
|
105
104
|
for (;;) {
|
|
106
105
|
if (cursor >= bytes.length) {
|
|
@@ -119,51 +118,10 @@ function skipIndefinite(bytes, start, majorType) {
|
|
|
119
118
|
throw new MalformedCborSeqError("indefinite-length string chunks cannot themselves be indefinite-length");
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
|
-
cursor = skipItem(bytes, cursor
|
|
121
|
+
cursor = skipItem(bytes, cursor, majorType === 2 || majorType === 3 ? depth : depth + 1);
|
|
123
122
|
if (majorType === 5) {
|
|
124
|
-
cursor = skipItem(bytes, cursor); // map value half of the pair
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/** Read the argument (length/count/tag-number/value) encoded by
|
|
129
|
-
* `additionalInfo` starting at `offset`. `additionalInfo <= 23` means
|
|
130
|
-
* it's inline in the initial byte already consumed by the caller; 24,
|
|
131
|
-
* 25, 26, 27 mean 1, 2, 4, 8 big-endian bytes follow respectively.
|
|
132
|
-
* Exported so `./cbor-seq`'s tag-header detection can reuse the exact
|
|
133
|
-
* same argument-decoding logic rather than a second copy of it. */
|
|
134
|
-
export function readArgument(bytes, offset, additionalInfo) {
|
|
135
|
-
if (additionalInfo <= 23) {
|
|
136
|
-
return { value: additionalInfo, next: offset };
|
|
137
|
-
}
|
|
138
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
139
|
-
switch (additionalInfo) {
|
|
140
|
-
case 24:
|
|
141
|
-
requireBytes(bytes, offset + 1);
|
|
142
|
-
return { value: view.getUint8(offset), next: offset + 1 };
|
|
143
|
-
case 25:
|
|
144
|
-
requireBytes(bytes, offset + 2);
|
|
145
|
-
return { value: view.getUint16(offset, false), next: offset + 2 };
|
|
146
|
-
case 26:
|
|
147
|
-
requireBytes(bytes, offset + 4);
|
|
148
|
-
return { value: view.getUint32(offset, false), next: offset + 4 };
|
|
149
|
-
case 27: {
|
|
150
|
-
requireBytes(bytes, offset + 8);
|
|
151
|
-
const big = view.getBigUint64(offset, false);
|
|
152
|
-
if (big > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
153
|
-
throw new MalformedCborSeqError("cbor-seq item length/count exceeds what this scanner supports");
|
|
154
|
-
}
|
|
155
|
-
return { value: Number(big), next: offset + 8 };
|
|
123
|
+
cursor = skipItem(bytes, cursor, depth + 1); // map value half of the pair
|
|
156
124
|
}
|
|
157
|
-
default:
|
|
158
|
-
// 28-30 are reserved; 31 (indefinite) is handled by the caller
|
|
159
|
-
// before `readArgument` is ever reached.
|
|
160
|
-
throw new MalformedCborSeqError(`reserved additional info ${additionalInfo}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
function requireBytes(bytes, endOffsetExclusive) {
|
|
164
|
-
if (endOffsetExclusive > bytes.length) {
|
|
165
|
-
throw new NeedMoreBytesError();
|
|
166
125
|
}
|
|
167
|
-
return endOffsetExclusive;
|
|
168
126
|
}
|
|
169
127
|
//# sourceMappingURL=cbor-item.js.map
|
package/dist/cbor-item.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cbor-item.js","sourceRoot":"","sources":["../src/cbor-item.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"cbor-item.js","sourceRoot":"","sources":["../src/cbor-item.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,2DAA2D;AAC3D,oEAAoE;AACpE,0EAA0E;AAC1E,4EAA4E;AAC5E,4DAA4D;AAC5D,EAAE;AACF,uEAAuE;AACvE,4DAA4D;AAE5D,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE7F;;;;;kFAKkF;AAClF,MA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AAI,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YAC3B,MAAM,IAAI,kBAAkB,EAAE,CAAC;QACjC,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;YAC3B,OAAO,MAAM,GAAG,CAAC,CAAC,CAAC,QAAQ;QAC7B,CAAC;QACD,IAAI,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YACvC,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAE,IAAI,CAAC,CAAC;YAC3C,MAAM,mBAAmB,GAAG,KAAK,CAAC,MAAM,CAAE,GAAG,IAAI,CAAC;YAClD,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;gBACjC,MAAM,IAAI,qBAAqB,CAC7B,iDAAiD,cAAc,cAAc,SAAS,EAAE,CACzF,CAAC;YACJ,CAAC;YACD,IAAI,mBAAmB,KAAK,EAAE,EAAE,CAAC;gBAC/B,MAAM,IAAI,qBAAqB,CAC7B,wEAAwE,CACzE,CAAC;YACJ,CAAC;QACH,CAAC;QACD,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACzF,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YACpB,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,6BAA6B;QAC5E,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/cbor-seq.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class CborSeqBoundaryScanner {
|
|
|
14
14
|
private buffer;
|
|
15
15
|
/** Append `chunk` and return every complete top-level item now
|
|
16
16
|
* available, oldest first. Throws (a `MalformedCborSeqError`) only
|
|
17
|
-
* for
|
|
17
|
+
* for invalid CBOR framing or text, or excessive nesting — a truncated final item
|
|
18
18
|
* just stays buffered, it never throws here. */
|
|
19
19
|
feedChunk(chunk: Uint8Array): Uint8Array[];
|
|
20
20
|
/** Bytes currently buffered, waiting for a frame to complete. Check
|
package/dist/cbor-seq.js
CHANGED
|
@@ -32,7 +32,7 @@ export class CborSeqBoundaryScanner {
|
|
|
32
32
|
buffer = new Uint8Array(0);
|
|
33
33
|
/** Append `chunk` and return every complete top-level item now
|
|
34
34
|
* available, oldest first. Throws (a `MalformedCborSeqError`) only
|
|
35
|
-
* for
|
|
35
|
+
* for invalid CBOR framing or text, or excessive nesting — a truncated final item
|
|
36
36
|
* just stays buffered, it never throws here. */
|
|
37
37
|
feedChunk(chunk) {
|
|
38
38
|
this.buffer = concatBytes(this.buffer, chunk);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cratestack/ts-types",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Shared TypeScript interfaces for CrateStack's generated RPC client (RpcLink, RpcLinkRequest, wire frame shapes). Types only — compiles to near-empty JS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|