You are here

function encrypt_get_key_from_key_provider in Encrypt 7.2

Same name and namespace in other branches
  1. 7.3 encrypt.module \encrypt_get_key_from_key_provider()

Get the key from a key provider.

Parameters

mixed $provider: The key provider to retrieve the key for. Can be either the fully-loaded provider (from encrypt_get_key_provider() or the name of the provider. If NULL, it assumes the default key provider.

array $config: The selected configuration.

Return value

string The key.

1 call to encrypt_get_key_from_key_provider()
_encrypt_decrypt in includes/encrypt.encrypt.inc
Private internal function to Encrypt and Decrypt text.

File

./encrypt.module, line 497
Main Encrypt Drupal File.

Code

function encrypt_get_key_from_key_provider($provider = NULL, $provider_settings = array(), array $config = array()) {
  $keys =& drupal_static(__FUNCTION__);
  if (!is_array($provider)) {
    $provider = encrypt_get_key_provider($provider);
  }

  // Get a hash for this combination of provider name and settings.
  $provider_hash = md5(json_encode(array(
    $provider['name'],
    $provider_settings,
  )));

  // If the key provider allows static variable storage, try to
  // retrieve the key from the static variable.
  if ($provider['static key'] && isset($keys[$provider_hash])) {
    $key = $keys[$provider_hash];
  }

  // If the key was not set from static variable storage,
  // retrieve it from the key provider.
  if (!isset($key)) {
    $key_function = ctools_plugin_get_function($provider, 'key callback');
    $key = call_user_func($key_function, $provider_settings, $config);

    // If the key provider allows static variable storage, set the
    // static variable.
    if ($provider['static key']) {
      $keys[$provider_hash] = $key;
    }
  }
  return $key;
}