summaryrefslogtreecommitdiff
path: root/sid.ml
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2018-10-29 00:48:03 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2018-10-30 01:15:03 +0100
commit269cef804819e9aef1c2d6642b26c87f306cb176 (patch)
treeb7a3b118ecafb06d7e3350690c3c99f52681f67a /sid.ml
parent7aa81d2a490e161082f3c38c9d0e806d841caca2 (diff)
downloadocaml-sid-269cef804819e9aef1c2d6642b26c87f306cb176.tar.gz
sid: sid_test: move conversion functions to result
Get rid of all “StringFmt” APIs involving exceptions. There is now only the “decode” function which returns a result type.
Diffstat (limited to 'sid.ml')
-rw-r--r--sid.ml37
1 files changed, 20 insertions, 17 deletions
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)