summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sid.ml14
1 files changed, 12 insertions, 2 deletions
diff --git a/sid.ml b/sid.ml
index 17c8124..0bcba50 100644
--- a/sid.ml
+++ b/sid.ml
@@ -92,7 +92,12 @@ module Con_strict = struct
let name = "strict"
let parse_hex_ia s p =
- assert (p <= String.length s - ident_auth_hexlen);
+ if p > String.length s - ident_auth_hexlen then
+ raise (Invalid_argument
+ (Printf.sprintf
+ "Invalid SID [%s]: conformant string encoding mandates \
+ exactly 12 hex digits"
+ s)) else
let e = p + ident_auth_hexlen - 1 in
let b = Bytes.make ident_auth_hexlen '\x2a' in
Bytes.set b 0 '0'; (* hex indicator for U64.of_string *)
@@ -240,9 +245,14 @@ module MkStringFmt (Con : Conformance) = struct
Con.name (U64.to_string ia))) else
p, ia
+ (* Below constant determines the lowest length at which it is sensible
+ to test for the “-0x…” component that indicates a hex encoded ia. We
+ require at least one hex digit to allow non-conformant parsing modes. *)
+ let min_hexlen = String.length "S-1-0xf"
+
let read_ident_auth s p =
let r = String.length s - p in
- if r < ident_auth_hexlen then ident_auth_decimal s p else (* hex can’t fit *)
+ if r < min_hexlen then ident_auth_decimal s p else
match s.[p], s.[p+1] with
| '0', 'x' -> read_ident_auth_hex s p
| _ -> ident_auth_decimal s p