PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / lib / packages / Base64Url / Base64Url.php

Base64Url.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/Base64Url/Base64Url.php

57 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * The MIT License (MIT)
7 *
8 * Copyright (c) 2014-2020 Spomky-Labs
9 *
10 * This software may be modified and distributed under the terms
11 * of the MIT license. See the LICENSE file for details.
12 */
13
14 namespace WP_DEFENDER_VENDOR\Base64Url;
15
16 use function base64_decode;
17 use function base64_encode;
18 use InvalidArgumentException;
19 use function rtrim;
20 use function strtr;
21
22 /**
23 * Encode and decode data into Base64 Url Safe.
24 */
25 final class Base64Url
26 {
27 /**
28 * @param string $data The data to encode
29 * @param bool $usePadding If true, the "=" padding at end of the encoded value are kept, else it is removed
30 *
31 * @return string The data encoded
32 */
33 public static function encode(string $data, bool $usePadding = false): string
34 {
35 $encoded = strtr(base64_encode($data), '+/', '-_');
36
37 return true === $usePadding ? $encoded : rtrim($encoded, '=');
38 }
39
40 /**
41 * @param string $data The data to decode
42 *
43 * @throws InvalidArgumentException
44 *
45 * @return string The data decoded
46 */
47 public static function decode(string $data): string
48 {
49 $decoded = base64_decode(strtr($data, '-_', '+/'), true);
50 if (false === $decoded) {
51 throw new InvalidArgumentException('Invalid data provided');
52 }
53
54 return $decoded;
55 }
56 }
57