| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Webauthn\Util; |
| 6 | |
| 7 | use ParagonIE\ConstantTime\Base64UrlSafe; |
| 8 | use Throwable; |
| 9 | use Webauthn\Exception\InvalidDataException; |
| 10 | |
| 11 | abstract class Base64 |
| 12 | { |
| 13 | public static function decode(string $data): string |
| 14 | { |
| 15 | try { |
| 16 | return Base64UrlSafe::decode($data); |
| 17 | } catch (Throwable) { |
| 18 | } |
| 19 | |
| 20 | try { |
| 21 | return \ParagonIE\ConstantTime\Base64::decode($data); |
| 22 | } catch (Throwable $e) { |
| 23 | throw InvalidDataException::create($data, 'Invalid data submitted', $e); |
| 24 | } |
| 25 | } |
| 26 | } |