(
payload: Uint8Array,
state: { offset: number }
)
| 214 | ) >>> 0 |
| 215 | |
| 216 | const readField = ( |
| 217 | payload: Uint8Array, |
| 218 | state: { offset: number } |
| 219 | ): Effect.Effect<Uint8Array, EventLogSessionAuthError> => { |
| 220 | if (state.offset + constLengthPrefixBytes > payload.byteLength) { |
| 221 | return Effect.fail( |
| 222 | new EventLogSessionAuthError({ |
| 223 | reason: "InvalidPayload", |
| 224 | message: "Session auth payload is truncated before field length" |
| 225 | }) |
| 226 | ) |
| 227 | } |
| 228 | |
| 229 | const length = readLength(payload, state.offset) |
| 230 | state.offset += constLengthPrefixBytes |
| 231 | |
| 232 | if (state.offset + length > payload.byteLength) { |
| 233 | return Effect.fail( |
| 234 | new EventLogSessionAuthError({ |
| 235 | reason: "InvalidPayload", |
| 236 | message: "Session auth payload is truncated inside a field" |
| 237 | }) |
| 238 | ) |
| 239 | } |
| 240 | |
| 241 | const field = payload.slice(state.offset, state.offset + length) |
| 242 | state.offset += length |
| 243 | return Effect.succeed(field) |
| 244 | } |
| 245 | |
| 246 | const bytesToHex = (bytes: Uint8Array): string => { |
| 247 | let hex = "" |
no test coverage detected