You are here

class MultiKeyWrapper in Lockr 7.3

Same name and namespace in other branches
  1. 7.2 vendor/lockr/lockr-client/src/KeyWrapper/MultiKeyWrapper.php \Lockr\KeyWrapper\MultiKeyWrapper

Hierarchy

Expanded class hierarchy of MultiKeyWrapper

1 file declares its use of MultiKeyWrapper
Lockr.php in vendor/lockr/lockr/src/Lockr.php

File

vendor/lockr/lockr/src/KeyWrapper/MultiKeyWrapper.php, line 4

Namespace

Lockr\KeyWrapper
View source
class MultiKeyWrapper implements KeyWrapperInterface {
  private static $wrappers = [
    LockrAes256CbcSha256RawKeyWrapper::PREFIX => LockrAes256CbcSha256RawKeyWrapper::class,
    LockrAes256CbcSha256KeyWrapper::PREFIX => LockrAes256CbcSha256KeyWrapper::class,
    LockrAes128CtrSha256KeyWrapper::PREFIX => LockrAes128CtrSha256KeyWrapper::class,
    '' => LockrAesCbcKeyWrapper::class,
  ];

  /**
   * {@inheritdoc}
   */
  public static function enabled() {
    foreach (self::$wrappers as $wrapper) {
      if ($wrapper::enabled()) {
        return true;
      }
    }
    return false;
  }

  /**
   * {@inheritdoc}
   */
  public static function encrypt($plaintext, $key = null) {
    foreach (self::$wrappers as $wrapper) {
      if ($wrapper::enabled()) {
        return $wrapper::encrypt($plaintext, $key);
      }
    }
    return false;
  }

  /**
   * {@inheritdoc}
   */
  public static function reencrypt($plaintext, $wrapping_key) {
    foreach (self::$wrappers as $prefix => $wrapper) {
      if (!$prefix || strpos($wrapping_key, $prefix) === 0) {
        return $wrapper::reencrypt($plaintext, $wrapping_key);
      }
    }
    return false;
  }

  /**
   * {@inheritdoc}
   */
  public static function decrypt($ciphertext, $wrapping_key) {
    foreach (self::$wrappers as $prefix => $wrapper) {
      if (!$prefix || strpos($wrapping_key, $prefix) === 0) {
        return $wrapper::decrypt($ciphertext, $wrapping_key);
      }
    }
    return false;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MultiKeyWrapper::$wrappers private static property
MultiKeyWrapper::decrypt public static function Decrypt the given ciphertext. Overrides KeyWrapperInterface::decrypt
MultiKeyWrapper::enabled public static function Overrides KeyWrapperInterface::enabled
MultiKeyWrapper::encrypt public static function Encrypt the given plaintext. Overrides KeyWrapperInterface::encrypt
MultiKeyWrapper::reencrypt public static function Encrypt the given plaintext reusing state. Overrides KeyWrapperInterface::reencrypt