ParagonIE_Sodium_File
- Source
wp-includes/sodium_compat/src/File.php:9
Class ParagonIE_Sodium_File
Compatibility
- WordPress
- core
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Methods · 21
- box()Box a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box(), but produces the same result.
- box_open()Open a boxed file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box_open(), but produces the same result.
- box_seal()Seal a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box_seal(), but produces the same result.
- box_seal_open()Open a sealed file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box_seal_open(), but produces the same result.
- generichash()Calculate the BLAKE2b hash of a file.
- secretbox()Encrypt a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_secretbox(), but produces the same result.
- secretbox_open()Seal a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_secretbox_open(), but produces the same result.
- sign()Sign a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_detached(), but produces the same result.
- verify()Verify a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_verify_detached(), but produces the same result.
- box_encrypt()
- box_decrypt()
- secretbox_encrypt()Encrypt a file
- secretbox_decrypt()Decrypt a file
- onetimeauth_verify()
- updateHashWithFile()Update a hash context with the contents of a file, without loading the entire file into memory.
- sign_core32()Sign a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_detached(), but produces the same result. (32-bit)
- verify_core32()Verify a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_verify_detached(), but produces the same result. (32-bit)
- secretbox_encrypt_core32()Encrypt a file (32-bit)
- secretbox_decrypt_core32()Decrypt a file (32-bit)
- onetimeauth_verify_core32()One-time message authentication for 32-bit systems
- ftell()
Source code
class ParagonIE_Sodium_File extends ParagonIE_Sodium_Core_Util{ /* PHP's default buffer size is 8192 for fread()/fwrite(). */ const BUFFER_SIZE = 8192; /** * Box a file (rather than a string). Uses less memory than * ParagonIE_Sodium_Compat::crypto_box(), but produces * the same result. * * @param string $inputFile Absolute path to a file on the filesystem * @param string $outputFile Absolute path to a file on the filesystem * @param string $nonce Number to be used only once * @param string $keyPair ECDH secret key and ECDH public key concatenated * * @return bool * @throws SodiumException * @throws TypeError */ public static function box( $inputFile, $outputFile, $nonce, #[\SensitiveParameter] $keyPair ) { /* Type checks: */ if (!is_string($inputFile)) { throw new TypeError('Argument 1 must be a string, ' . gettype($inputFile) . ' given.'); } if (!is_string($outputFile)) { throw new TypeError('Argument 2 must be a string, ' . gettype($outputFile) . ' given.'); } if (!is_string($nonce)) { throw new TypeError('Argument 3 must be a string, ' . gettype($nonce) . ' given.'); } /* Input validation: */ if (!is_string($keyPair)) { throw new TypeError('Argument 4 must be a string, ' . gettype($keyPair) . ' given.'); } if (self::strlen($nonce) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_NONCEBYTES) { throw new TypeError('Argument 3 must be CRYPTO_BOX_NONCEBYTES bytes'); } if (self::strlen($keyPair) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES) { throw new TypeError('Argument 4 must be CRYPTO_BOX_KEYPAIRBYTES bytes'); } /** @var int $size */ $size = filesize($inputFile); if (!is_int($size)) { throw new SodiumException('Could not obtain the file size'); } /** @var resource $ifp */ $ifp = fopen($inputFile, 'rb'); if (!is_resource($ifp)) { throw new SodiumException('Could not open input file for reading'); } /** @var resource $ofp */ $ofp = fopen($outputFile, 'wb'); if (!is_resource($ofp)) { fclose($ifp); throw new SodiumException('Could not open output file for writing'); } $res = self::box_encrypt($ifp, $ofp, $size, $nonce, $keyPair); fclose($ifp); fclose($ofp); return $res; } /** * Open a boxed file (rather than a string). Uses less memory than * ParagonIE_Sodium_Compat::crypto_box_open(), but produces * the same result. * * Warning: Does not protect against TOCTOU attacks. You should * just load the file into memory and use crypto_box_open() ifChangelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/sodium_compat/src/File.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.