Libs changes for php 8.x

This commit is contained in:
Sumit Panwar
2025-05-23 10:46:00 +05:30
parent 178e8fa28a
commit fa0a498733
1185 changed files with 92175 additions and 58962 deletions

View File

@@ -9,7 +9,10 @@ final class Key
const KEY_CURRENT_VERSION = "\xDE\xF0\x00\x00";
const KEY_BYTE_SIZE = 32;
private $key_bytes = null;
/**
* @var string
*/
private $key_bytes;
/**
* Creates new random key.
@@ -26,15 +29,27 @@ final class Key
/**
* Loads a Key from its encoded form.
*
* By default, this function will call Encoding::trimTrailingWhitespace()
* to remove trailing CR, LF, NUL, TAB, and SPACE characters, which are
* commonly appended to files when working with text editors.
*
* @param string $saved_key_string
* @param bool $do_not_trim (default: false)
*
* @throws Ex\BadFormatException
* @throws Ex\EnvironmentIsBrokenException
*
* @return Key
*/
public static function loadFromAsciiSafeString($saved_key_string)
public static function loadFromAsciiSafeString(
#[\SensitiveParameter]
$saved_key_string,
$do_not_trim = false
)
{
if (!$do_not_trim) {
$saved_key_string = Encoding::trimTrailingWhitespace($saved_key_string);
}
$key_bytes = Encoding::loadBytesFromChecksummedAsciiSafeString(self::KEY_CURRENT_VERSION, $saved_key_string);
return new Key($key_bytes);
}
@@ -71,13 +86,15 @@ final class Key
*
* @throws Ex\EnvironmentIsBrokenException
*/
private function __construct($bytes)
private function __construct(
#[\SensitiveParameter]
$bytes
)
{
if (Core::ourStrlen($bytes) !== self::KEY_BYTE_SIZE) {
throw new Ex\EnvironmentIsBrokenException(
'Bad key length.'
);
}
Core::ensureTrue(
Core::ourStrlen($bytes) === self::KEY_BYTE_SIZE,
'Bad key length.'
);
$this->key_bytes = $bytes;
}