bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MD5


From: Pete French
Subject: Re: MD5
Date: Thu, 23 Jan 2003 11:09:50 +0000

> Actually, base includes md5.c/h and I was wondering whether it would be 
> better if we added a set of categories to base's NSData to return md5 
> digests of NSData.  It seems that the c-api would be available but 
> nothing in base seems to use it yet.  (At least I couldn't find it.)  If 
> the only reason this hasn't been done is because simply no one has done 
> it yet, then I could try to hack up an implementation.

I've done it for my own foundation kit...

In the data object:

- (PFString*)md5String
{
        return [PFString stringWithMD5OfBytes:[self bytes]
                        length:[self length]];
}

And in the string object:

+ stringWithMD5OfBytes:(const unsigned char*)data length:(unsigned int)len
{
        id retval;
        char buffer[64];
        MD5Data(data, len, buffer);
        retval = [[self alloc] initWithUtf8:buffer];
        [retval autorelease];   
        return retval;
}

MD5Data returns a null terminated string so this is fine. You need
to later the method names to correspond to the ones in OpenStep rather
than mymore quirky home-grow versions, but this should do the trick nicely.

Adding the digesting as a class method onto PFString lets me get MD5
digests of any arvbitrary chunk of bytes. For example I have another method
on the PFString object which digests the string.

- (PFString*)md5String
{
        return [[self class] stringWithMD5OfBytes:__c_string
                        length:__c_string_len];
}

I store all strings in UTF8 though, as __c_string with __c_string_len
bytes in the object (that way it works with the "xyz" stuff out of the box,
and under Windows NT too)

feel free to add this into GNustep if its useful.

-bat.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]