Sys.Signals module for a Variant type of signals (and a set_signal function that...
[ocaml.git] / stdlib / digest.ml
blob78a45d54ee78cb5560a03f159134e35a4702c7aa
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
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. *)
11 (* *)
12 (***********************************************************************)
14 (* $Id$ *)
16 (* Message digest (MD5) *)
18 type t = string
20 external unsafe_string: string -> int -> int -> t = "caml_md5_string"
21 external channel: in_channel -> int -> t = "caml_md5_chan"
23 let string str =
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
31 let file filename =
32 let ic = open_in_bin filename in
33 let d = channel ic (-1) in
34 close_in ic;
37 let output chan digest =
38 output chan digest 0 16
40 let input chan =
41 let digest = String.create 16 in
42 really_input chan digest 0 16;
43 digest
45 let to_hex d =
46 let result = String.create 32 in
47 for i = 0 to 15 do
48 String.blit (Printf.sprintf "%02x" (int_of_char d.[i])) 0 result (2*i) 2;
49 done;
50 result