Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Digest function to transform a md5sum string into a Digest.t #8285

Closed
vicuna opened this issue Sep 15, 2003 · 1 comment

Comments

Projects
None yet
1 participant
@vicuna
Copy link

commented Sep 15, 2003

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

@vicuna

This comment has been minimized.

Copy link
Author

commented Jan 26, 2012

Comment author: @damiendoligez

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

@vicuna vicuna closed this Jan 26, 2012

@vicuna vicuna added the feature-wish label Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.