ParagonIE_Sodium_Compat::increment

Advertisement

Summery Summery

Increase a string (little endian)

Syntax Syntax

ParagonIE_Sodium_Compat::increment( string $var )

Parameters Parameters

$var

(Required)

Return Return

(void)

Source Source

File: wp-includes/sodium_compat/src/Compat.php

    public static function increment(&$var)
    {
        /* Type checks: */
        ParagonIE_Sodium_Core_Util::declareScalarType($var, 'string', 1);

        if (self::useNewSodiumAPI()) {
            sodium_increment($var);
            return;
        }
        if (self::use_fallback('increment')) {
            $func = '\\Sodium\\increment';
            $func($var);
            return;
        }

        $len = ParagonIE_Sodium_Core_Util::strlen($var);
        $c = 1;
        $copy = '';
        for ($i = 0; $i < $len; ++$i) {
            $c += ParagonIE_Sodium_Core_Util::chrToInt(
                ParagonIE_Sodium_Core_Util::substr($var, $i, 1)
            );
            $copy .= ParagonIE_Sodium_Core_Util::intToChr($c);
            $c >>= 8;
        }
        $var = $copy;
    }

Advertisement

Advertisement

Leave a Reply