From 11538e85baba398cb75f3f30c4c47ed0d995ad2f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Wed, 19 Aug 2015 14:44:11 -0400 Subject: [PATCH] lib/md5: update to only rely on the light FFI MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/md5.nit | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/md5.nit b/lib/md5.nit index 41de768..cd6bcd4 100644 --- a/lib/md5.nit +++ b/lib/md5.nit @@ -492,23 +492,24 @@ in "C Header" `{ redef class String # returns the md5 digest of the receiver string # algorithm implemented by L. Peter Deutsch - fun md5: String import String.to_cstring, NativeString.to_s `{ + fun md5: String do return to_cstring.native_md5.to_s +end + +redef class NativeString + private fun native_md5: NativeString `{ md5_state_t state; md5_byte_t digest[16]; /* result */ char *hex_output = malloc(33*sizeof(char)); int di; - char *in_text; - - in_text = String_to_cstring(self); md5_init(&state); - md5_append(&state, (const md5_byte_t *)in_text, strlen(in_text)); + md5_append(&state, (const md5_byte_t *)self, strlen(self)); md5_finish(&state, digest); for (di = 0; di < 16; ++di) sprintf(hex_output + di * 2, "%02x", digest[di]); hex_output[32] = '\0'; - return NativeString_to_s(hex_output); + return hex_output; `} end -- 1.7.9.5