abstract class BaseMethod in DRD Agent 8.3
Same name and namespace in other branches
- 4.0.x src/Crypt/BaseMethod.php \Drupal\drd_agent\Crypt\BaseMethod
Provides base encryption method.
Hierarchy
- class \Drupal\drd_agent\Crypt\BaseMethod implements BaseMethodInterface
Expanded class hierarchy of BaseMethod
3 files declare their use of BaseMethod
- MCrypt.php in src/
Crypt/ Method/ MCrypt.php - OpenSSL.php in src/
Crypt/ Method/ OpenSSL.php - TLS.php in src/
Crypt/ Method/ TLS.php
File
- src/
Crypt/ BaseMethod.php, line 13
Namespace
Drupal\drd_agent\CryptView source
abstract class BaseMethod implements BaseMethodInterface {
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
/**
* BaseMethod constructor.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
*/
public function __construct(ContainerInterface $container) {
$this->container = $container;
/** @noinspection NullPointerExceptionInspection */
$this->logger = $container
->get('logger.factory')
->get('DRD Agent');
}
/**
* Callback to encrypt and decrypt files.
*
* @param string $mode
* This is "-e" to encrypt or "-d" to decrypt.
* @param string $in
* Input filename.
* @param string $out
* Output filename.
*
* @return int
* Exit code of the openssl command.
*/
private function cryptFileExecute($mode, $in, $out) : int {
$output = [];
$cmd = [
'openssl',
$this
->getCipher(),
$mode,
'-a',
'-salt',
'-in',
$in,
'-out',
$out,
'-k',
base64_encode($this
->getPassword()),
];
exec(implode(' ', $cmd), $output, $ret);
return $ret;
}
/**
* {@inheritdoc}
*/
public function encryptFile($filename) : string {
if ($this
->getCipher()) {
exec('openssl version', $output, $ret);
if ($ret === 0) {
$in = $filename;
$filename .= '.openssl';
if ($this
->cryptFileExecute('-e', $in, $filename) !== 0) {
$filename = $in;
}
}
}
return $filename;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BaseMethod:: |
protected | property | ||
BaseMethod:: |
protected | property | ||
BaseMethod:: |
private | function | Callback to encrypt and decrypt files. | |
BaseMethod:: |
public | function |
Encrypt a file. Overrides BaseMethodInterface:: |
|
BaseMethod:: |
public | function | BaseMethod constructor. | 2 |
BaseMethodInterface:: |
public | function | Decode, decrypt and unserialize arguments from the other end. | 3 |
BaseMethodInterface:: |
public | function | Encrypt and encode any list of arguments. | 3 |
BaseMethodInterface:: |
public | function | Get the selected cipher. | 3 |
BaseMethodInterface:: |
public | function | Get a list of available cipher methods. | 3 |
BaseMethodInterface:: |
public | function | Get an initialiation vector. | 3 |
BaseMethodInterface:: |
public | function | Get the crypt method label. | 3 |
BaseMethodInterface:: |
public | function | Get the password. | 3 |
BaseMethodInterface:: |
public | function | Find out if the crypt method is available. | 3 |