equal
deleted
inserted
replaced
6 implementation. |
6 implementation. |
7 *) |
7 *) |
8 |
8 |
9 structure SHA1: SHA1 = |
9 structure SHA1: SHA1 = |
10 struct |
10 struct |
|
11 |
|
12 (* digesting *) |
11 |
13 |
12 fun hex_digit i = if i < 10 then chr (ord "0" + i) else chr (ord "a" + i - 10); |
14 fun hex_digit i = if i < 10 then chr (ord "0" + i) else chr (ord "a" + i - 10); |
13 |
15 |
14 fun hex_string arr i = |
16 fun hex_string arr i = |
15 let val c = CInterface.fromCchar (CInterface.offset i CInterface.Cchar arr) |
17 let val c = CInterface.fromCchar (CInterface.offset i CInterface.Cchar arr) |
26 CInterface.call3 (CInterface.get_sym (File.platform_path lib_path) "sha1_buffer") |
28 CInterface.call3 (CInterface.get_sym (File.platform_path lib_path) "sha1_buffer") |
27 (CInterface.STRING, CInterface.LONG, CInterface.POINTER) |
29 (CInterface.STRING, CInterface.LONG, CInterface.POINTER) |
28 CInterface.POINTER (str, size str, CInterface.address digest); |
30 CInterface.POINTER (str, size str, CInterface.address digest); |
29 in fold (suffix o hex_string digest) (0 upto 19) "" end; |
31 in fold (suffix o hex_string digest) (0 upto 19) "" end; |
30 |
32 |
31 fun digest str = digest_external str |
33 fun digest_string str = digest_external str |
32 handle CInterface.Foreign msg => |
34 handle CInterface.Foreign msg => |
33 (warning (msg ^ "\nUsing slow ML implementation of SHA1.digest"); SHA1.digest str); |
35 (warning (msg ^ "\nUsing slow ML implementation of SHA1.digest"); SHA1.rep (SHA1.digest str)); |
|
36 |
|
37 |
|
38 (* type digest *) |
|
39 |
|
40 datatype digest = Digest of string; |
|
41 |
|
42 val digest = Digest o digest_string; |
|
43 fun rep (Digest s) = s; |
34 |
44 |
35 end; |
45 end; |