1 (***********************************************************************)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the GNU Library General Public License, with *)
10 (* the special exception on linking described in file ../LICENSE. *)
12 (***********************************************************************)
16 (* Message digest (MD5) *)
20 external unsafe_string
: string -> int -> int -> t
= "caml_md5_string"
21 external channel
: in_channel
-> int -> t
= "caml_md5_chan"
24 unsafe_string str
0 (String.length str
)
26 let substring str ofs len
=
27 if ofs
< 0 || len
< 0 || ofs
> String.length str
- len
28 then invalid_arg
"Digest.substring"
29 else unsafe_string str ofs len
32 let ic = open_in_bin filename
in
33 let d = channel
ic (-1) in
37 let output chan digest
=
38 output chan digest
0 16
41 let digest = String.create
16 in
42 really_input chan
digest 0 16;
46 let result = String.create
32 in
48 String.blit
(Printf.sprintf
"%02x" (int_of_char
d.[i
])) 0 result (2*i
) 2;