wppaste
WordPress

ParagonIE_Sodium_Core_Base64_UrlSafe

Source
wp-includes/sodium_compat/src/Core/Base64/UrlSafe.php:9
Class ParagonIE_Sodium_Core_Base64UrlSafe

Description

Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)

Compatibility

WordPress
core
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Methods · 7

Source code

class ParagonIE_Sodium_Core_Base64_UrlSafe{    // COPY ParagonIE_Sodium_Core_Base64_Common STARTING HERE    /**     * Encode into Base64     *     * Base64 character set "[A-Z][a-z][0-9]+/"     *     * @param string $src     * @return string     * @throws TypeError     */    public static function encode($src)    {        return self::doEncode($src, true);    }     /**     * Encode into Base64, no = padding     *     * Base64 character set "[A-Z][a-z][0-9]+/"     *     * @param string $src     * @return string     * @throws TypeError     */    public static function encodeUnpadded($src)    {        return self::doEncode($src, false);    }     /**     * @param string $src     * @param bool $pad   Include = padding?     * @return string     * @throws TypeError     */    protected static function doEncode($src, $pad = true)    {        $dest = '';        $srcLen = ParagonIE_Sodium_Core_Util::strlen($src);        // Main loop (no padding):        for ($i = 0; $i + 3 <= $srcLen; $i += 3) {            /** @var array<int, int> $chunk */            $chunk = unpack('C*', ParagonIE_Sodium_Core_Util::substr($src, $i, 3));            $b0 = $chunk[1];            $b1 = $chunk[2];            $b2 = $chunk[3];             $dest .=                self::encode6Bits(               $b0 >> 2       ) .                self::encode6Bits((($b0 << 4) | ($b1 >> 4)) & 63) .                self::encode6Bits((($b1 << 2) | ($b2 >> 6)) & 63) .                self::encode6Bits(  $b2                     & 63);        }        // The last chunk, which may have padding:        if ($i < $srcLen) {            /** @var array<int, int> $chunk */            $chunk = unpack('C*', ParagonIE_Sodium_Core_Util::substr($src, $i, $srcLen - $i));            $b0 = $chunk[1];            if ($i + 1 < $srcLen) {                $b1 = $chunk[2];                $dest .=                    self::encode6Bits($b0 >> 2) .                    self::encode6Bits((($b0 << 4) | ($b1 >> 4)) & 63) .                    self::encode6Bits(($b1 << 2) & 63);                if ($pad) {                    $dest .= '=';                }            } else {                $dest .=                    self::encode6Bits( $b0 >> 2) .                    self::encode6Bits(($b0 << 4) & 63);                if ($pad) {                    $dest .= '==';                }            }        }        return $dest;    }

Changelog

One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.9.7
Method decodeNoPadding() added.verified against source

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/sodium_compat/src/Core/Base64/UrlSafe.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.