You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 1835 Reporter: administrator Status: closed (set by @damiendoligez on 2012-01-26T22:57:07Z) Resolution: fixed Priority: normal Severity: feature Fixed in version: 3.13.0+dev Category: ~DO NOT USE (was: OCaml general)
Bug description
Hello,
I think that a usefull addition to the Digest module would be one that
allowed to transform a 32 character md5sum string (as outputed by md5sum
for example) into a Digest.t.
I have here a quick and dirty implementation of such a function :
let md5sum_of_string s =
let digest = String.make 16 (char_of_int 0) in
let len = String.length s in
if len <> 32 then failwith "Not a md5sum" else
let int_of_hex c = match c with
| '0' .. '9' -> (int_of_char c) - 48
| 'a' .. 'f' -> (int_of_char c) - 87
| 'A' .. 'F' -> (int_of_char c) - 55
| _ -> failwith "Not an hex"
in
let rec convert_byte i =
if i = 0 then () else begin
digest.[i-1] <- char_of_int
((int_of_hex s.[2i-1]) + 16 * (int_of_hex s.[2i-2]));
convert_byte (i-1)
end
in
convert_byte 16;
digest
It is not very elegant, and may not be endian clean or something such,
but it does the job, and i include it here to more explain what i meant.
Maybe this can be added still in time for 3.07.
Friendly,
Sven Luther
The text was updated successfully, but these errors were encountered:
Original bug ID: 1835
Reporter: administrator
Status: closed (set by @damiendoligez on 2012-01-26T22:57:07Z)
Resolution: fixed
Priority: normal
Severity: feature
Fixed in version: 3.13.0+dev
Category: ~DO NOT USE (was: OCaml general)
Bug description
Hello,
I think that a usefull addition to the Digest module would be one that
allowed to transform a 32 character md5sum string (as outputed by md5sum
for example) into a Digest.t.
I have here a quick and dirty implementation of such a function :
let md5sum_of_string s =
let digest = String.make 16 (char_of_int 0) in
let len = String.length s in
if len <> 32 then failwith "Not a md5sum" else
let int_of_hex c = match c with
| '0' .. '9' -> (int_of_char c) - 48
| 'a' .. 'f' -> (int_of_char c) - 87
| 'A' .. 'F' -> (int_of_char c) - 55
| _ -> failwith "Not an hex"
in
let rec convert_byte i =
if i = 0 then () else begin
digest.[i-1] <- char_of_int
((int_of_hex s.[2i-1]) + 16 * (int_of_hex s.[2i-2]));
convert_byte (i-1)
end
in
convert_byte 16;
digest
It is not very elegant, and may not be endian clean or something such,
but it does the job, and i include it here to more explain what i meant.
Maybe this can be added still in time for 3.07.
Friendly,
Sven Luther
The text was updated successfully, but these errors were encountered: