From 269cef804819e9aef1c2d6642b26c87f306cb176 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 29 Oct 2018 00:48:03 +0100 Subject: sid: sid_test: move conversion functions to result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Get rid of all “StringFmt” APIs involving exceptions. There is now only the “decode” function which returns a result type. --- sid.ml | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'sid.ml') diff --git a/sid.ml b/sid.ml index 430393d..a2590fd 100644 --- a/sid.ml +++ b/sid.ml @@ -85,23 +85,26 @@ module StringFmt = struct Error (Printf.sprintf "Invalid SID: ‘%s’ too short to be a SID in string format" s) - else - expect_char s 'S' 0; - expect_char s '-' 1; - expect_char s '1' 2; - expect_char s '-' 3; - let p = 4 in - let p, ia = read_decimal_u64 s p in - let sa = ref [] and p' = ref p in - while !p' < n && List.length !sa < max_subauth_count do - expect_char s '-' !p'; - let np, d = read_decimal_u32 s (!p' + 1) in - sa := d :: !sa; - p' := np - done; - Ok { sid_ident_auth = ia - ; sid_sub_auths = Array.of_list (List.rev !sa) - } + else begin + try + expect_char s 'S' 0; + expect_char s '-' 1; + expect_char s '1' 2; + expect_char s '-' 3; + let p = 4 in + let p, ia = read_decimal_u64 s p in + let sa = ref [] and p' = ref p in + while !p' < n && List.length !sa < max_subauth_count do + expect_char s '-' !p'; + let np, d = read_decimal_u32 s (!p' + 1) in + sa := d :: !sa; + p' := np + done; + Ok { sid_ident_auth = ia + ; sid_sub_auths = Array.of_list (List.rev !sa) + } + with Invalid_argument e -> Error e; + end let fmt_ident_auth b ia = Buffer.add_string b (U64.to_string ia) -- cgit v1.2.3