[Top][All Lists]

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

Re: MD5

From: Richard Frith-Macdonald
Subject: Re: MD5
Date: Fri, 24 Jan 2003 10:36:18 +0000

On Friday, January 24, 2003, at 10:13  am, David Ayers wrote:
Currently base exports -(NSData *)MD5Digest (but personnally I would have preferred md5Digest :-)...)

I'm happy to change that.... will do it next.

>| - (NSString *)md5StringUsingEncoding: (NSStringEncoding) enc;

>| - (NSString *)md5String; /* uses default encoding.*/

As regards other methods, my feeling is that most of them are trivial and should not really be put in the base library
(or common additions).

I like the idea you (I think) suggested in an earlier email, of a new category method of NSData ...

- (NSString*)hexadecimalRepresentation;

Then to get a hexadecimal digest of any string you would just write -

myDigest = [[[myString dataUsingEncoding: myStringEncoding] md5Digest] hexadecimalRepresentation];

though perhaps it should be ...

- (NSData*)hexadecimalRepresentation;

So that the above code to generate 'myDigest' would return an NSData object containing 32 bytes of ascii hexadecimal values that could easily be plugged into an email message, and you could get a string value by myStringDigest = AUTORELEASE([[NSString alloc] initWithData: myDigest encoding: NSASCIIStringEncoding]);

While we could obviously have some convenience methods encapsulating this, my impulse is to keep the API as small and simple as possible, and write code like that above, making it clearer what the code is doing.

I don't want to be dogmatic about it though ... if the majority of people want to include several convenience methods,
I'll do that.

What are the preferences about a hexadecimal representation method returning NSString or NSData ?

reply via email to

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