[Zope-dev] Incorrect Padding?

Shane Hathaway shane@digicool.com
Mon, 24 Jul 2000 16:02:52 -0400


Steve Alexander wrote:
> 
> Chris Withers wrote:
> >
> > So what was causing the original error then?
> 
> string.split('basic')[-1] was returning 'basic'.
> 
> base64.decodestring('basic') causes an "Incorrect padding" error.
> 
> base64.decodestring('basic ') causes an "Incorrect padding" error too.
> 
> Martijn Pieters wrote:
> > We partly agree, and this is tricky. Unauthorised is wrong, it should return a
> > Bad Request (or whatever the correct HTTP error is in this case). File a
> > patch! =)
> 
> I've attached a patch to lib/python/AccessControl/User.py. If there are
> no suggestions of improvements, or complaints :-)  I'll stick it into
> the Collector.

Mention in the collector that the padding that's incorrect doesn't
refer to spaces, but to equal signs.  The ASCII representation of
base64 is in sets of 4 characters, which translate to 3 bytes.  If the
ASCII data is of a length that doesn't evenly divide by 4, the string
is supposed to end with equal signs as "padding".  If it doesn't,
you'll get the "incorrect padding" error.

Incidentally, try the following:

base64.decodestring('basic===')

This products gibberish, but it does work. :-)

Shane