Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
Base64Url | |
0.00% |
0 / 5 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
encode | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
decode | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Utils\Encoding |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Utils\Encoding; |
16 | |
17 | /** |
18 | * Base64Url encoding class |
19 | * |
20 | * @package phpOMS\Utils\Encoding |
21 | * @license OMS License 2.0 |
22 | * @link https://jingga.app |
23 | * @since 1.0.0 |
24 | */ |
25 | final class Base64Url |
26 | { |
27 | /** |
28 | * Encode source text |
29 | * |
30 | * @param string $source Source to encode |
31 | * |
32 | * @return string |
33 | * |
34 | * @since 1.0.0 |
35 | */ |
36 | public static function encode(string $source) : string |
37 | { |
38 | $data64 = \base64_encode($source); |
39 | $data64Url = \strtr($data64, '+/', '-_'); |
40 | |
41 | return \rtrim($data64Url, '='); |
42 | } |
43 | |
44 | /** |
45 | * Dedecodes text |
46 | * |
47 | * @param string $b64 Encoded value to dedecode |
48 | * |
49 | * @return string |
50 | * |
51 | * @since 1.0.0 |
52 | */ |
53 | public static function decode(string $b64) : string |
54 | { |
55 | $data = \strtr($b64, '-_', '+/'); |
56 | |
57 | return \base64_decode($data, false); |
58 | } |
59 | } |