From: Mark Wooding Date: Sat, 10 Aug 2013 12:29:41 +0000 (+0100) Subject: httpauth.py: Use `base64' module's built-in character twiddles. X-Git-Tag: 1.0.2~3 X-Git-Url: https://git.distorted.org.uk/~mdw/chopwood/commitdiff_plain/40c5485b01a84b8a6b83f0e63576039cb856a36c httpauth.py: Use `base64' module's built-in character twiddles. I hadn't noticed before: `b64encode' has an optional argument which you can use to change the `+' and `/' characters. Use them instead of a post-pass with `str.replace'. --- diff --git a/httpauth.py b/httpauth.py index ea978eb..6bb3ec8 100644 --- a/httpauth.py +++ b/httpauth.py @@ -149,9 +149,7 @@ def freshsecret(): def hack_octets(s): """Return the octet string S, in a vaguely pretty form.""" - return BN.b64encode(s) \ - .rstrip('=') \ - .replace('/', '$') + return BN.b64encode(s, '+$').rstrip('=') def auth_tag(sec, stamp, nonce, user): """Compute a tag using secret SEC on `STAMP.NONCE.USER'."""