PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.8
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / myyoast-client / infrastructure / encoding / base64url.php

base64url.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.8, at src/myyoast-client/infrastructure/encoding/base64url.php

43 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3
4 namespace Yoast\WP\SEO\MyYoast_Client\Infrastructure\Encoding;
5
6 /**
7 * Base64url encoding and decoding per RFC 7515 / RFC 4648 Section 5.
8 *
9 * Provides URL-safe, unpadded Base64 encoding as required by JWTs, JWKs,
10 * PKCE challenges, and other OAuth/OIDC constructs.
11 */
12 class Base64url {
13
14 /**
15 * Encodes data using base64url (URL-safe, no padding).
16 *
17 * @param string $data The data to encode.
18 *
19 * @return string The base64url-encoded string.
20 */
21 public static function encode( string $data ): string {
22 // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Base64URL encoding per RFC 7515.
23 return \rtrim( \strtr( \base64_encode( $data ), '+/', '-_' ), '=' );
24 }
25
26 /**
27 * Decodes a base64url-encoded string.
28 *
29 * @param string $data The base64url-encoded string.
30 *
31 * @return string|false The decoded data, or false on failure.
32 */
33 public static function decode( string $data ) {
34 $remainder = ( \strlen( $data ) % 4 );
35 if ( $remainder !== 0 ) {
36 $data .= \str_repeat( '=', ( 4 - $remainder ) );
37 }
38
39 // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode -- Base64URL decoding per RFC 7515.
40 return \base64_decode( \strtr( $data, '-_', '+/' ), true );
41 }
42 }
43