You are here

function aes_load_phpsec in AES encryption 7

Same name and namespace in other branches
  1. 6 aes.module \aes_load_phpsec()

Loads phpseclib.

Return value

bool|int TRUE on success, negative error code if something went wrong.

3 calls to aes_load_phpsec()
aes_config in ./aes.admin.inc
Inits aes_config form.
aes_decrypt in ./aes.module
Decrypts a string of encrypted data.
aes_encrypt in ./aes.module
Encrypts a string.

File

./aes.module, line 73
Main file of the AES encryption module.

Code

function aes_load_phpsec() {

  // Find out where this module is located and set up an include path for the
  // phpsec library.
  if (module_exists('libraries') && libraries_get_path('phpseclib')) {
    $phpsec_include_path = libraries_get_path('phpseclib');
  }
  else {
    $phpsec_include_path = dirname(__FILE__) . '/phpseclib';
  }

  // Include phpsec AES lib.
  if (file_exists($phpsec_include_path . '/Crypt/AES.php') === FALSE) {
    return -2;
  }
  if (is_readable($phpsec_include_path . '/Crypt/AES.php') === FALSE) {
    drupal_set_message(t("It appears that phpseclib is installed in the right location but can't be read. Check that the permissions on the directory and its files allows for reading by the webserver."));
    return -3;
  }
  if (function_exists("set_include_path") == FALSE) {

    // If we don't have set_include_path then we're out of luck.
    return -1;
  }
  set_include_path(get_include_path() . PATH_SEPARATOR . $phpsec_include_path);
  include_once 'Crypt/AES.php';
  return TRUE;
}