aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-09-04 07:32:01 +0000
committerMario <mario@mariovavti.com>2021-09-04 07:32:01 +0000
commit5dcf053b4c3b054a6e52d580ad10a0b9de135d3b (patch)
treed22d630a0763bcb4ca5e3981d98f2f29dcbe58cb /include
parent8a3446c02144a624b462f2e4afd0e1961a834bb6 (diff)
downloadvolse-hubzilla-5dcf053b4c3b054a6e52d580ad10a0b9de135d3b.tar.gz
volse-hubzilla-5dcf053b4c3b054a6e52d580ad10a0b9de135d3b.tar.bz2
volse-hubzilla-5dcf053b4c3b054a6e52d580ad10a0b9de135d3b.zip
implement strict mode for base64url_decode() and introduce unpack_link_id()
Diffstat (limited to 'include')
-rw-r--r--include/text.php23
1 files changed, 19 insertions, 4 deletions
diff --git a/include/text.php b/include/text.php
index e0910f83e..bd2df45aa 100644
--- a/include/text.php
+++ b/include/text.php
@@ -2156,12 +2156,12 @@ function base64url_encode($s, $strip_padding = true) {
return $s;
}
-function base64url_decode($s) {
+function base64url_decode($s, $strict = false) {
if(is_array($s)) {
logger('base64url_decode: illegal input: ' . print_r(debug_backtrace(), true));
return $s;
}
- return base64_decode(strtr($s,'-_','+/'));
+ return base64_decode(strtr($s,'-_','+/'), $strict);
}
@@ -2175,12 +2175,12 @@ function base64special_encode($s, $strip_padding = true) {
return $s;
}
-function base64special_decode($s) {
+function base64special_decode($s, $strict = false) {
if(is_array($s)) {
logger('base64url_decode: illegal input: ' . print_r(debug_backtrace(), true));
return $s;
}
- return base64_decode(strtr($s,',.','+/'));
+ return base64_decode(strtr($s,',.','+/'), $strict);
}
/**
@@ -3589,6 +3589,21 @@ function gen_link_id($mid) {
return $mid;
}
+/**
+ * @brief check if the provided string starts with 'b64.' and try to decode it if so.
+ * If it could be decoded return the decoded string or false if decoding failed.
+ * If the string does not start with 'b64.', return the string as is.
+ *
+ * @param string $mid
+ * @return string|boolean false
+ */
+function unpack_link_id($mid) {
+ if (is_string($mid) && strpos($mid, 'b64.') === 0) {
+ $mid = @base64url_decode(substr($mid, 4), true);
+ return $mid;
+ }
+ return $mid;
+}
// callback for array_walk