You are here

function commerce_ups_encryption_available in Commerce UPS 7

Same name and namespace in other branches
  1. 7.2 commerce_ups.module \commerce_ups_encryption_available()

Check whether encryption is available.

1 call to commerce_ups_encryption_available()
commerce_ups_settings_form in ./commerce_ups.admin.inc

File

./commerce_ups.module, line 230

Code

function commerce_ups_encryption_available($options = array()) {
  $defaults = array(
    'check_config' => TRUE,
    'display_errors' => FALSE,
    'display_warnings' => FALSE,
    'display_all' => FALSE,
    'fail_threshold' => 'warnings',
  );
  $options = array_merge($defaults, $options);
  extract($options);
  $errors = array();
  $warnings = array();
  if (!module_exists('aes')) {
    $errors[] = 'AES Encryption module is not installed.';
  }
  elseif ($check_config) {
    if (!variable_get('aes_key_path', FALSE) || variable_get('aes_key_storage_method', FALSE) != 'File') {
      $warnings[] = 'AES Encryption is installed but not configured securely. Please go ' . l('configure AES Encryption to use file storage', 'admin/settings/aes') . ' to enable encryption for UPS credentials.';
    }
  }
  if ($display_errors || $display_all) {
    foreach ($errors as $msg) {
      drupal_set_message(filter_xss(t($msg)), 'error', FALSE);
    }
  }
  if ($display_warnings || $display_all) {
    foreach ($warnings as $msg) {
      drupal_set_message(filter_xss(t($msg)), 'warning', FALSE);
    }
  }
  switch ($fail_threshold) {
    case 'errors':
      if (empty($errors)) {
        return TRUE;
      }
    case 'warnings':
      if (empty($errors) && empty($warnings)) {
        return TRUE;
      }
  }
}