Skip to content

Commit

Permalink
Bump php requirement to 7.4 for boxpacking support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Oct 25, 2024
1 parent 73e7e94 commit 759ba53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static function get_excluded_methods() {
* @return bool
*/
public static function is_packing_supported() {
return version_compare( phpversion(), '7.1', '>=' ) && apply_filters( 'woocommerce_gzd_enable_rucksack_packaging', true );
return version_compare( phpversion(), '7.4', '>=' ) && apply_filters( 'woocommerce_gzd_enable_rucksack_packaging', true );
}

public static function is_integration() {
Expand Down
17 changes: 17 additions & 0 deletions src/SecretBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
namespace Vendidero\Germanized\Shipments;

class SecretBox {

public static function supports_storing_secrets() {
return function_exists( 'sodium_crypto_secretbox_keygen' ) && defined( 'SODIUM_CRYPTO_PWHASH_SALTBYTES' );
}

public static function get_encryption_key_notice( $encryption_type = '', $explanation = '' ) {
$notice = '';

Expand Down Expand Up @@ -103,6 +108,13 @@ public static function has_valid_encryption_key( $encryption_type = '' ) {
* @return string|\WP_Error
*/
public static function encrypt( $message, $encryption_type = '' ) {
if ( ! self::supports_storing_secrets() ) {
$error = new \WP_Error();
$error->add( 'secrets-not-supported', 'Client does not support storing secrets.' );

return self::log_error( $error );
}

try {
$key_data = self::get_encryption_key_data( $encryption_type );
$nonce = random_bytes( SODIUM_CRYPTO_SECRETBOX_NONCEBYTES );
Expand Down Expand Up @@ -133,6 +145,11 @@ public static function decrypt( $cipher, $encryption_type = '' ) {
$decoded = base64_decode( $cipher ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
$error = new \WP_Error();

if ( ! self::supports_storing_secrets() ) {
$error->add( 'secrets-not-supported', 'Client does not support storing secrets.' );
return self::log_error( $error );
}

if ( false === $decoded ) {
$error->add( 'decrypt-decode', 'Error while decoding the encrypted message.' );
return self::log_error( $error );
Expand Down

0 comments on commit 759ba53

Please sign in to comment.