MCPcopy Create free account
hub / github.com/WICG/webpackage / deterministicRec

Function deterministicRec

js/sign/src/cbor/deterministic.ts:29–50  ·  view source on GitHub ↗
(input: Uint8Array, index: number)

Source from the content-addressed store, hash-verified

27// CBOR item starting from the given index. Returns the length of the CBOR item
28// in bytes.
29function deterministicRec(input: Uint8Array, index: number): number {
30 const b = input[index];
31
32 switch (getMajorType(b)) {
33 case MajorType.PosInt: {
34 const { lengthInBytes } = unsignedIntegerDeterministic(input, index);
35 return lengthInBytes + 1;
36 }
37 case MajorType.ByteString:
38 case MajorType.Text:
39 return textOrByteStringDeterministic(input, index) + 1;
40
41 case MajorType.Array:
42 return arrayDeterministic(input, index);
43
44 case MajorType.Map:
45 return mapDeterministic(input, index);
46
47 default:
48 throw new Error('Missing implementation for a major type.');
49 }
50}
51
52// unsignedIntegerDeterministic calculates the value of the unsigned integer to ensure that
53// the right amount of bytes is used in the CBOR encoding. It returns both,

Callers 3

checkDeterministicFunction · 0.70
arrayDeterministicFunction · 0.70
mapDeterministicFunction · 0.70

Calls 5

getMajorTypeFunction · 0.90
arrayDeterministicFunction · 0.70
mapDeterministicFunction · 0.70

Tested by

no test coverage detected