( input: Uint8Array, index: number )
| 105 | // Returns length of the text or byte string element in bytes for which its |
| 106 | // deterministicy has been ensured. |
| 107 | function textOrByteStringDeterministic( |
| 108 | input: Uint8Array, |
| 109 | index: number |
| 110 | ): number { |
| 111 | // lengthInBytes is the length of the number representing the length of the |
| 112 | // text/byte string. |
| 113 | const { lengthInBytes, value } = unsignedIntegerDeterministic(input, index); |
| 114 | const totalLength = lengthInBytes + Number(value); |
| 115 | |
| 116 | if (totalLength >= input.length - index) { |
| 117 | throw new Error( |
| 118 | "Text or byte string's length cannot exceed the number of bytes left on the input array." |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | return totalLength; |
| 123 | } |
| 124 | |
| 125 | // Returns length of the CBOR array in bytes and checks that each item on it |
| 126 | // follows the deterministic principles. |
no test coverage detected