ParagonIE_Sodium_Core_Util::load_3

Advertisement

Summery Summery

Load a 3 character substring into an integer

Syntax Syntax

ParagonIE_Sodium_Core_Util::load_3( string $string )

Parameters Parameters

$string

(string) (Required)

Return Return

(int)

Source Source

File: wp-includes/sodium_compat/src/Core/Util.php

    public static function load_3($string)
    {
        /* Type checks: */
        if (!is_string($string)) {
            throw new TypeError('Argument 1 must be a string, ' . gettype($string) . ' given.');
        }

        /* Input validation: */
        if (self::strlen($string) < 3) {
            throw new RangeException(
                'String must be 3 bytes or more; ' . self::strlen($string) . ' given.'
            );
        }
        /** @var array<int, int> $unpacked */
        $unpacked = unpack('V', $string . "\0");
        return (int) ($unpacked[1] & 0xffffff);
    }

Advertisement

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.