author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
9 | 1 |
<?php |
2 |
||
18 | 3 |
if (PHP_VERSION_ID < 70000) { |
4 |
if (!is_callable('sodiumCompatAutoloader')) { |
|
5 |
/** |
|
6 |
* Sodium_Compat autoloader. |
|
7 |
* |
|
8 |
* @param string $class Class name to be autoloaded. |
|
9 |
* |
|
10 |
* @return bool Stop autoloading? |
|
11 |
*/ |
|
12 |
function sodiumCompatAutoloader($class) |
|
13 |
{ |
|
14 |
$namespace = 'ParagonIE_Sodium_'; |
|
15 |
// Does the class use the namespace prefix? |
|
16 |
$len = strlen($namespace); |
|
17 |
if (strncmp($namespace, $class, $len) !== 0) { |
|
18 |
// no, move to the next registered autoloader |
|
19 |
return false; |
|
20 |
} |
|
21 |
||
22 |
// Get the relative class name |
|
23 |
$relative_class = substr($class, $len); |
|
24 |
||
25 |
// Replace the namespace prefix with the base directory, replace namespace |
|
26 |
// separators with directory separators in the relative class name, append |
|
27 |
// with .php |
|
28 |
$file = dirname(__FILE__) . '/src/' . str_replace('_', '/', $relative_class) . '.php'; |
|
29 |
// if the file exists, require it |
|
30 |
if (file_exists($file)) { |
|
31 |
require_once $file; |
|
32 |
return true; |
|
33 |
} |
|
9 | 34 |
return false; |
35 |
} |
|
36 |
||
18 | 37 |
// Now that we have an autoloader, let's register it! |
38 |
spl_autoload_register('sodiumCompatAutoloader'); |
|
9 | 39 |
} |
18 | 40 |
} else { |
41 |
require_once dirname(__FILE__) . '/autoload-php7.php'; |
|
9 | 42 |
} |
43 |
||
18 | 44 |
/* Explicitly, always load the Compat class: */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
45 |
if (!class_exists('ParagonIE_Sodium_Compat', false)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
46 |
require_once dirname(__FILE__) . '/src/Compat.php'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
47 |
} |
18 | 48 |
|
49 |
if (!class_exists('SodiumException', false)) { |
|
50 |
require_once dirname(__FILE__) . '/src/SodiumException.php'; |
|
51 |
} |
|
9 | 52 |
if (PHP_VERSION_ID >= 50300) { |
53 |
// Namespaces didn't exist before 5.3.0, so don't even try to use this |
|
54 |
// unless PHP >= 5.3.0 |
|
55 |
require_once dirname(__FILE__) . '/lib/namespaced.php'; |
|
56 |
require_once dirname(__FILE__) . '/lib/sodium_compat.php'; |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
57 |
if (!defined('SODIUM_CRYPTO_AEAD_AEGIS128L_KEYBYTES')) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
58 |
require_once dirname(__FILE__) . '/lib/php84compat_const.php'; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
59 |
} |
16 | 60 |
} else { |
61 |
require_once dirname(__FILE__) . '/src/PHP52/SplFixedArray.php'; |
|
9 | 62 |
} |
63 |
if (PHP_VERSION_ID < 70200 || !extension_loaded('sodium')) { |
|
16 | 64 |
if (PHP_VERSION_ID >= 50300 && !defined('SODIUM_CRYPTO_SCALARMULT_BYTES')) { |
65 |
require_once dirname(__FILE__) . '/lib/php72compat_const.php'; |
|
66 |
} |
|
67 |
if (PHP_VERSION_ID >= 70000) { |
|
68 |
assert(class_exists('ParagonIE_Sodium_Compat'), 'Possible filesystem/autoloader bug?'); |
|
69 |
} else { |
|
70 |
assert(class_exists('ParagonIE_Sodium_Compat')); |
|
71 |
} |
|
18 | 72 |
require_once(dirname(__FILE__) . '/lib/php72compat.php'); |
73 |
} elseif (!function_exists('sodium_crypto_stream_xchacha20_xor')) { |
|
74 |
// Older versions of {PHP, ext/sodium} will not define these |
|
75 |
require_once(dirname(__FILE__) . '/lib/php72compat.php'); |
|
9 | 76 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
77 |
if (PHP_VERSION_ID < 80400 || !extension_loaded('sodium')) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
78 |
require_once dirname(__FILE__) . '/lib/php84compat.php'; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
79 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
80 |
require_once(dirname(__FILE__) . '/lib/stream-xchacha20.php'); |
18 | 81 |
require_once(dirname(__FILE__) . '/lib/ristretto255.php'); |