Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001835OCamlOCaml generalpublic2003-09-15 21:172012-01-26 23:57
Reporteradministrator 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version3.13.0+dev 
Summary0001835: Digest function to transform a md5sum string into a Digest.t
DescriptionHello,

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.[2*i-1]) + 16 * (int_of_hex s.[2*i-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

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0006815)
doligez (administrator)
2012-01-26 23:57

Implemented as Digest.from_hex in trunk [3.13.0] (commit 12082).

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue
2012-01-26 23:57 doligez Note Added: 0006815
2012-01-26 23:57 doligez Status acknowledged => closed
2012-01-26 23:57 doligez Resolution open => fixed
2012-01-26 23:57 doligez Fixed in Version => 3.13.0+dev
2012-01-26 23:57 doligez Description Updated View Revisions


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker