httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <...@algroup.co.uk>
Subject Re: ap_md5() function is rather useless
Date Sat, 05 Sep 1998 15:55:28 GMT
Rasmus Lerdorf wrote:
> 
> > Huh? ap_md5() is for strings. C strings. That's why the name of the
> > argument is "string". That's why the comment in the function says "Take
> > the Md5 hash of the string argument." That's why it uses ap_pstrdup. Which
> > also takes strings. I'd guess half that of C functions existing
> > in the world today work on strings. If you pass them binary data, they
> > don't work. That doesn't mean they are buggy. Just that they only work on
> > null-terminated C strings.
> >
> > If you want a version of ap_md5() that works on non-strings, then write
> > one. I don't see the big deal.
> 
> But it is a trivial change to make the current one binary safe.  Sort of
> silly to restrict it to strings only where there is no decent reason to.
> I don't really care though.  It was more as a convenience to other module
> writers.  I have my own binary-safe md5() function.

Sure, it makes sense, but the way to do it is this:

API_EXPORT(char *) ap_md5_binary(pool *p, unsigned char *buf,int len)
	{
	...
	}

API_EXPORT(char *) ap_md5(pool *p, unsigned char *string)
	{
	return ap_md5_binary(p,string,strlen(string));
	}

or even #define ap_md5 (but there's a small danger from side-effects if
you do that). Then you get the function you want _and_ retain upwards
compatibility _and_ avoid code duplication.

Cheeers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686| Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org/
and Technical Director|Email: ben@algroup.co.uk |
A.L. Digital Ltd,     |Apache-SSL author     http://www.apache-ssl.org/
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache/

WE'RE RECRUITING! http://www.aldigital.co.uk/

Mime
View raw message