| 1 |
<?php |
| 2 |
|
| 3 |
spl_autoload_register(function ($class) { |
| 4 |
$namespace = 'ParagonIE_Sodium_'; |
| 5 |
|
| 6 |
$len = strlen($namespace); |
| 7 |
if (strncmp($namespace, $class, $len) !== 0) { |
| 8 |
|
| 9 |
return false; |
| 10 |
} |
| 11 |
|
| 12 |
|
| 13 |
$relative_class = substr($class, $len); |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
$file = dirname(__FILE__) . '/src/' . str_replace('_', '/', $relative_class) . '.php'; |
| 19 |
|
| 20 |
if (file_exists($file)) { |
| 21 |
require_once $file; |
| 22 |
return true; |
| 23 |
} |
| 24 |
return false; |
| 25 |
}); |
| 26 |
|
| 27 |
|
| 28 |
if (!class_exists('ParagonIE_Sodium_Compat', false)) { |
| 29 |
require_once dirname(__FILE__) . '/src/Compat.php'; |
| 30 |
} |
| 31 |
if (!class_exists('ParagonIE_Sodium_File', false)) { |
| 32 |
require_once dirname(__FILE__) . '/src/File.php'; |
| 33 |
} |
| 34 |
|
| 35 |
if (!class_exists('SodiumException', false)) { |
| 36 |
require_once dirname(__FILE__) . '/src/SodiumException.php'; |
| 37 |
} |
| 38 |
|
| 39 |
if (!defined('SODIUM_CRYPTO_AEAD_AEGIS128L_KEYBYTES')) { |
| 40 |
require_once dirname(__FILE__) . '/lib/php84compat_const.php'; |
| 41 |
} |
| 42 |
|
| 43 |
if (!extension_loaded('sodium')) { |
| 44 |
if (!defined('SODIUM_CRYPTO_SCALARMULT_BYTES')) { |
| 45 |
require_once dirname(__FILE__) . '/lib/php72compat_const.php'; |
| 46 |
} |
| 47 |
assert(class_exists('ParagonIE_Sodium_Compat'), 'Possible filesystem/autoloader bug?'); |
| 48 |
require_once(dirname(__FILE__) . '/lib/php72compat.php'); |
| 49 |
} elseif (!function_exists('sodium_crypto_stream_xchacha20_xor')) { |
| 50 |
|
| 51 |
require_once(dirname(__FILE__) . '/lib/php72compat.php'); |
| 52 |
} |
| 53 |
if (PHP_VERSION_ID < 80400 || !extension_loaded('sodium')) { |
| 54 |
require_once dirname(__FILE__) . '/lib/php84compat.php'; |
| 55 |
} |
| 56 |
require_once(dirname(__FILE__) . '/lib/stream-xchacha20.php'); |
| 57 |
require_once(dirname(__FILE__) . '/lib/ristretto255.php'); |