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

Function arrayDeterministic

go/internal/cbor/deterministic.go:128–149  ·  view source on GitHub ↗

arrayDeterministic returns length of the CBOR array in bytes and checks that each item on it follows the deterministic principles.

(input []byte)

Source from the content-addressed store, hash-verified

126
127// arrayDeterministic returns length of the CBOR array in bytes and checks that each item on it follows the deterministic principles.
128func arrayDeterministic(input []byte) (int, error) {
129 lenOfNumOfItems, numOfItems, err := unsignedIntegerDeterministic(input)
130 if err != nil {
131 return 0, err
132 }
133
134 // Skip the starter byte and the bytes stating the amount of elements the array has.
135 startIndexOfNextElement := 1 + lenOfNumOfItems
136
137 for arrElementIndex := 0; arrElementIndex < int(numOfItems); arrElementIndex++ {
138 if startIndexOfNextElement >= len(input) {
139 panic("Number of items on CBOR array is less than the number of items it claims.")
140 }
141 itemLength, err := deterministicRec(input[startIndexOfNextElement:])
142 if err != nil {
143 return 0, err
144 }
145 startIndexOfNextElement += itemLength
146 }
147
148 return startIndexOfNextElement, nil
149}
150
151// mapDeterministic returns length of the CBOR map in bytes and checks that each item on it
152// follows the deterministic principles. Additionally to ensure deterministicy of a map:

Callers 1

deterministicRecFunction · 0.70

Calls 2

deterministicRecFunction · 0.70

Tested by

no test coverage detected