aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/http/Base64Url.php
diff options
context:
space:
mode:
authorAurélien Tamisier <virtualtam+github@flibidi.net>2019-01-18 21:26:03 +0100
committerGitHub <noreply@github.com>2019-01-18 21:26:03 +0100
commitff3b5dc5542ec150f0d9b447394364a15e9156d0 (patch)
tree5e926e36816d510e3b3a10e20b94c23f43b55092 /application/http/Base64Url.php
parent1826e383ecf501302974132fd443cf1ca06e10f6 (diff)
parentdea72c711ff740b3b829d238fcf85648465143a0 (diff)
downloadShaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.gz
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.zst
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.zip
Merge pull request #1248 from virtualtam/refactor/namespacing
Ensure all PHP classes are properly namespaced
Diffstat (limited to 'application/http/Base64Url.php')
-rw-r--r--application/http/Base64Url.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/application/http/Base64Url.php b/application/http/Base64Url.php
new file mode 100644
index 00000000..33fa7c1f
--- /dev/null
+++ b/application/http/Base64Url.php
@@ -0,0 +1,35 @@
1<?php
2
3namespace Shaarli\Http;
4
5/**
6 * URL-safe Base64 operations
7 *
8 * @see https://en.wikipedia.org/wiki/Base64#URL_applications
9 */
10class Base64Url
11{
12 /**
13 * Base64Url-encodes data
14 *
15 * @param string $data Data to encode
16 *
17 * @return string Base64Url-encoded data
18 */
19 public static function encode($data)
20 {
21 return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
22 }
23
24 /**
25 * Decodes Base64Url-encoded data
26 *
27 * @param string $data Data to decode
28 *
29 * @return string Decoded data
30 */
31 public static function decode($data)
32 {
33 return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
34 }
35}