addons/auth_passkey/_vendor/webauthn/helpers/base64url_to_bytes.py
raw| 1 | from base64 import urlsafe_b64decode |
| 2 | |
| 3 | |
| 4 | def base64url_to_bytes(val: str) -> bytes: |
| 5 | """ |
| 6 | Convert a Base64URL-encoded string to bytes. |
| 7 | """ |
| 8 | # Padding is optional in Base64URL. Unfortunately, Python's decoder requires the |
| 9 | # padding. Given the fact that urlsafe_b64decode will ignore too _much_ padding, |
| 10 | # we can tack on a constant amount of padding to ensure encoded values can always be |
| 11 | # decoded. |
| 12 | return urlsafe_b64decode(f"{val}===") |