( input: Uint8Array, index: number )
| 53 | // the right amount of bytes is used in the CBOR encoding. It returns both, |
| 54 | // the length of the bytes array and the value of the unsigned integer. |
| 55 | function unsignedIntegerDeterministic( |
| 56 | input: Uint8Array, |
| 57 | index: number |
| 58 | ): { lengthInBytes: number; value: bigint } { |
| 59 | const info = convertToAdditionalInfo(input[index]); |
| 60 | const lengthInBytes = getAdditionalInfoLength(info); |
| 61 | const value = getUnsignedIntegerValue( |
| 62 | input.slice(index, index + lengthInBytes + /*add info byte*/ 1), |
| 63 | info |
| 64 | ); |
| 65 | |
| 66 | if (value < getAdditionalInfoValueLowerLimit(info)) { |
| 67 | throw new Error( |
| 68 | `${value} should not be represented with ${lengthInBytes} bytes in deterministic CBOR.` |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | return { lengthInBytes, value }; |
| 73 | } |
| 74 | |
| 75 | export function getUnsignedIntegerValue( |
| 76 | input: Uint8Array, |
no test coverage detected