-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
41 lines (36 loc) · 1.08 KB
/
functions.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
use Bakame\Aide\Base32\Base32;
defined('PHP_BASE32_ASCII') || define('PHP_BASE32_ASCII', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567');
defined('PHP_BASE32_HEX') || define('PHP_BASE32_HEX', '0123456789ABCDEFGHIJKLMNOPQRSTUV');
if (!function_exists('base32_encode')) {
/**
* @param non-empty-string $alphabet
* @param non-empty-string $padding
*/
function base32_encode(
string $decoded,
string $alphabet = PHP_BASE32_ASCII,
string $padding = '=',
): string {
return Base32::new($alphabet, $padding)->encode($decoded);
}
}
if (!function_exists('base32_decode')) {
/**
* @param non-empty-string $alphabet
* @param non-empty-string $padding
*/
function base32_decode(
string $encoded,
string $alphabet = PHP_BASE32_ASCII,
string $padding = '=',
bool $strict = false
): string|false {
try {
return Base32::new($alphabet, $padding)->decode($encoded, $strict);
} catch (RuntimeException) {
return false;
}
}
}