From 55f50ddaf31fe1cb4cda4d15e387280e8f7a8242 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 3 Nov 2018 19:58:42 +0100 Subject: sid: add channel handlers for binary representation --- sid.ml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'sid.ml') diff --git a/sid.ml b/sid.ml index 12d708a..0d5c89b 100644 --- a/sid.ml +++ b/sid.ml @@ -221,6 +221,32 @@ module PacketRep = struct (* [MS-DTYP] 2.4.22 *) ; sid_sub_auths = sas } + let from_channel ?(endian=Little) ic = + try + let v = input_byte ic in + if v <> 0x01 then + Error (Printf.sprintf + "input malformed: expected SID version=0x01, got 0x%0.2x" v) else + let nsa = input_byte ic in + if max_subauth_count < nsa then + Error (Printf.sprintf + "input malformed: up to %d subAuthority elements permitted, \ + %d specified" + max_subauth_count nsa) else + let n = sizeof_ident_auth + nsa * sizeof_sub_auth in + let b = Bytes.make (2 + n) '\x00' in + Bytes.set b 0 '\x01'; + Bytes.set b 1 (char_of_int nsa); + really_input ic b 2 n; + decode ~endian b + with End_of_file -> + Error (Printf.sprintf + "input malformed: unexpected end of file at offset %d \ + parsing SID" (pos_in ic)) + + let to_channel ?(endian=Little) oc s = + encode ~endian s |> output_bytes oc + end (* [module PacketRep] *) module WellKnown = struct -- cgit v1.2.3