Bundle Protocol Security (RFC 9172) - authentication and encryption for DTN
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(lint): extract helpers to reduce long functions (E005)

Extract helpers in bpsec.ml (parameter_of_cbor, security_block_of_cbor)
and claudeio transport/examples to bring function lengths under threshold.

+23 -22
+23 -22
lib/bpsec.ml
··· 231 231 | None -> Error (Invalid_result id))) 232 232 | _ -> Error (Cbor_error "result must be array of 2") 233 233 234 + let decode_parameters context_id context_flags elements = 235 + if context_flags.parameters_present then 236 + match Cbor.to_array (List.nth elements 4) with 237 + | Some param_cbors -> 238 + List.filter_map 239 + (fun c -> Result.to_option (parameter_of_cbor context_id c)) 240 + param_cbors 241 + | None -> [] 242 + else [] 243 + 244 + let decode_target_results context_id result_arrays = 245 + List.map 246 + (fun arr -> 247 + match Cbor.to_array arr with 248 + | Some result_cbors -> 249 + List.filter_map 250 + (fun c -> Result.to_option (result_of_cbor context_id c)) 251 + result_cbors 252 + | None -> []) 253 + result_arrays 254 + 234 255 let security_block_of_cbor cbor = 235 256 let* elements = 236 257 Cbor.to_array cbor |> require "security block must be array" ··· 256 277 let* source = 257 278 Bundle.eid_of_cbor (get 3) |> Result.map_error (fun msg -> Cbor_error msg) 258 279 in 259 - let param_idx = 4 in 280 + let parameters = decode_parameters context_id context_flags elements in 260 281 let result_idx = if context_flags.parameters_present then 5 else 4 in 261 - let parameters = 262 - if context_flags.parameters_present then 263 - match Cbor.to_array (get param_idx) with 264 - | Some param_cbors -> 265 - List.filter_map 266 - (fun c -> Result.to_option (parameter_of_cbor context_id c)) 267 - param_cbors 268 - | None -> [] 269 - else [] 270 - in 271 282 let* result_arrays = 272 283 Cbor.to_array (get result_idx) |> require "results must be array" 273 284 in 274 - let results = 275 - List.map 276 - (fun arr -> 277 - match Cbor.to_array arr with 278 - | Some result_cbors -> 279 - List.filter_map 280 - (fun c -> Result.to_option (result_of_cbor context_id c)) 281 - result_cbors 282 - | None -> []) 283 - result_arrays 284 - in 285 + let results = decode_target_results context_id result_arrays in 285 286 Ok { targets; context_id; context_flags; source; parameters; results } 286 287 287 288 (* {1 Crypto Operations} *)