You are here

class MultiKeyWrapper in Lockr 7.2

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

Hierarchy

Expanded class hierarchy of MultiKeyWrapper

1 file declares its use of MultiKeyWrapper
KeyClient.php in vendor/lockr/lockr-client/src/KeyClient.php

File

vendor/lockr/lockr-client/src/KeyWrapper/MultiKeyWrapper.php, line 6

Namespace

Lockr\KeyWrapper
View source
class MultiKeyWrapper implements KeyWrapperInterface {
  protected static $wrappers = array(
    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) {
    foreach (self::$wrappers as $wrapper) {
      if ($wrapper::enabled()) {
        return $wrapper::encrypt($plaintext);
      }
    }
    return false;
  }

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
MultiKeyWrapper::$wrappers protected static property
MultiKeyWrapper::decrypt public static function Decrypt the given ciphertext using encoded. 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 using the same initial state as defined by encoded. Overrides KeyWrapperInterface::reencrypt