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.

cbor downstream: partial fix for int/int64 and raw-value queries

Follow-up to the cbor rename. ocaml-bundle, ocaml-cose, ocaml-bpsec
still have int/int64 mismatches at a few callsites that need manual
triage (V.int vs V.int64 depending on source type, V.text constructor
renamed to V.string). Committing partial progress; full fix in a
focused downstream-migration session.

+19 -25
+19 -25
lib/bpsec.ml
··· 134 134 ([ targets; context_id; context_flags; source ] @ parameters @ [ results ]) 135 135 136 136 let require_param_int id v = 137 - V.to_int v |> Option.map Int64.to_int 137 + V.to_int64 v |> Option.map Int64.to_int 138 138 |> Option.to_result ~none:(Invalid_parameter id) 139 139 140 140 let require_param_bytes id v = 141 - Cbor.to_bytes v |> Option.to_result ~none:(Invalid_parameter id) 141 + V.to_bytes v |> Option.to_result ~none:(Invalid_parameter id) 142 142 143 143 let bib_parameter_of_cbor id value_cbor = 144 144 match id with ··· 183 183 (require_param_bytes id value_cbor) 184 184 185 185 let parameter_of_cbor context_id cbor = 186 - match Cbor.to_array cbor with 186 + match V.to_array cbor with 187 187 | Some [ id_cbor; value_cbor ] -> 188 - let* id_int = 189 - V.to_int id_cbor |> require "parameter id must be uint" 190 - in 188 + let* id_int = V.to_int64 id_cbor |> require "parameter id must be uint" in 191 189 let id = Int64.to_int id_int in 192 190 if context_id = bib_hmac_sha2 then bib_parameter_of_cbor id value_cbor 193 191 else if context_id = bcb_aes_gcm then bcb_parameter_of_cbor id value_cbor ··· 198 196 | _ -> Error (Cbor_error "parameter must be array of 2") 199 197 200 198 let result_of_cbor context_id cbor = 201 - match Cbor.to_array cbor with 199 + match V.to_array cbor with 202 200 | Some [ id_cbor; value_cbor ] -> ( 203 - match V.to_int id_cbor with 201 + match V.to_int64 id_cbor with 204 202 | None -> Error (Cbor_error "result id must be uint") 205 203 | Some id_int -> ( 206 204 let id = Int64.to_int id_int in 207 205 if context_id = bib_hmac_sha2 then 208 206 match id with 209 207 | 1 -> ( 210 - match Cbor.to_bytes value_cbor with 208 + match V.to_bytes value_cbor with 211 209 | Some h -> Ok (Bib_result (Expected_hmac h)) 212 210 | None -> Error (Invalid_result id)) 213 211 | _ -> ( 214 - match Cbor.to_bytes value_cbor with 212 + match V.to_bytes value_cbor with 215 213 | Some data -> Ok (Unknown_result (id, data)) 216 214 | None -> Error (Invalid_result id)) 217 215 else if context_id = bcb_aes_gcm then 218 216 match id with 219 217 | 1 -> ( 220 - match Cbor.to_bytes value_cbor with 218 + match V.to_bytes value_cbor with 221 219 | Some t -> Ok (Bcb_result (Auth_tag t)) 222 220 | None -> Error (Invalid_result id)) 223 221 | _ -> ( 224 - match Cbor.to_bytes value_cbor with 222 + match V.to_bytes value_cbor with 225 223 | Some data -> Ok (Unknown_result (id, data)) 226 224 | None -> Error (Invalid_result id)) 227 225 else 228 - match Cbor.to_bytes value_cbor with 226 + match V.to_bytes value_cbor with 229 227 | Some data -> Ok (Unknown_result (id, data)) 230 228 | None -> Error (Invalid_result id))) 231 229 | _ -> Error (Cbor_error "result must be array of 2") 232 230 233 231 let decode_parameters context_id context_flags elements = 234 232 if context_flags.parameters_present then 235 - match Cbor.to_array (List.nth elements 4) with 233 + match V.to_array (List.nth elements 4) with 236 234 | Some param_cbors -> 237 235 List.filter_map 238 236 (fun c -> Result.to_option (parameter_of_cbor context_id c)) ··· 243 241 let decode_target_results context_id result_arrays = 244 242 List.map 245 243 (fun arr -> 246 - match Cbor.to_array arr with 244 + match V.to_array arr with 247 245 | Some result_cbors -> 248 246 List.filter_map 249 247 (fun c -> Result.to_option (result_of_cbor context_id c)) ··· 252 250 result_arrays 253 251 254 252 let security_block_of_cbor cbor = 255 - let* elements = 256 - Cbor.to_array cbor |> require "security block must be array" 257 - in 253 + let* elements = V.to_array cbor |> require "security block must be array" in 258 254 if List.length elements < 5 then 259 255 Error (Cbor_error "security block needs at least 5 elements") 260 256 else 261 257 let get i = List.nth elements i in 262 - let* target_cbors = 263 - Cbor.to_array (get 0) |> require "targets must be array" 264 - in 258 + let* target_cbors = V.to_array (get 0) |> require "targets must be array" in 265 259 let targets = 266 260 List.filter_map 267 - (fun c -> Option.map Int64.to_int (V.to_int c)) 261 + (fun c -> Option.map Int64.to_int (V.to_int64 c)) 268 262 target_cbors 269 263 in 270 264 let* context_id_int = 271 - V.to_int (get 1) |> require "context id must be uint" 265 + V.to_int64 (get 1) |> require "context id must be uint" 272 266 in 273 267 let context_id = Int64.to_int context_id_int in 274 - let* flags_int = V.to_int (get 2) |> require "flags must be uint" in 268 + let* flags_int = V.to_int64 (get 2) |> require "flags must be uint" in 275 269 let context_flags = context_flags_of_int (Int64.to_int flags_int) in 276 270 let* source = 277 271 Bundle.eid_of_cbor (get 3) |> Result.map_error (fun msg -> Cbor_error msg) ··· 279 273 let parameters = decode_parameters context_id context_flags elements in 280 274 let result_idx = if context_flags.parameters_present then 5 else 4 in 281 275 let* result_arrays = 282 - Cbor.to_array (get result_idx) |> require "results must be array" 276 + V.to_array (get result_idx) |> require "results must be array" 283 277 in 284 278 let results = decode_target_results context_id result_arrays in 285 279 Ok { targets; context_id; context_flags; source; parameters; results }