(value)
| 60 | |
| 61 | |
| 62 | def decode(value): |
| 63 | if not isinstance(value, str): |
| 64 | raise ValueError("base64 member must be a string") |
| 65 | for altchars in (None, b"-_"): |
| 66 | try: |
| 67 | decoded = base64.b64decode(value, altchars=altchars, validate=True) |
| 68 | encoded = base64.b64encode(decoded, altchars=altchars).decode("ascii") |
| 69 | if value == encoded: |
| 70 | return decoded |
| 71 | except (ValueError, UnicodeError): |
| 72 | pass |
| 73 | raise ValueError("noncanonical base64") |
| 74 | |
| 75 | |
| 76 | def verify(raw, key_bytes): |