-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathdecode.php
26 lines (22 loc) · 928 Bytes
/
decode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
declare(strict_types=1);
namespace Psl\Encoding\Base64;
use Psl\Encoding\Exception;
/**
* Decode a base64-encoded string into raw binary.
*
* @pure
*
* @throws Exception\RangeException If the encoded string contains characters outside
* the base64 characters range.
* @throws Exception\IncorrectPaddingException If the encoded string has an incorrect padding.
*/
function decode(string $base64, Variant $variant = Variant::Standard, bool $explicit_padding = true): string
{
return match ($variant) {
Variant::Standard => Internal\Base64::decode($base64, $explicit_padding),
Variant::UrlSafe => Internal\Base64UrlSafe::decode($base64, $explicit_padding),
Variant::DotSlash => Internal\Base64DotSlash::decode($base64, $explicit_padding),
Variant::DotSlashOrdered => Internal\Base64DotSlashOrdered::decode($base64, $explicit_padding),
};
}