Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
CipherParams
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAlgorithmString
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
12
 generateIV
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 checkValidAlgorithm
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace Ably\Models;
3
4/**
5 * Cipher parameters.
6 * @see Crypto
7 */
8class CipherParams {
9    /** @var string Key used for encryption, may be a binary string. */
10    public $key;
11    /** @var string Algorithm to be used for encryption. The only officially supported algorithm is currently 'aes'. */
12    public $algorithm;
13    /** @var string Key length of the algorithm. Valid values for 'aes' are 128 or 256. */
14    public $keyLength;
15    /** @var string Algorithm mode. The only supported mode for 'aes' is currently 'cbc'. */
16    public $mode;
17    /** @var string Initialization vector for encryption, may be a binary string. */
18    public $iv;
19
20    public function __construct() {
21    }
22
23    /**
24     * @return string Algorithm string as required by openssl - for instance `aes-128-cbc`
25     */
26    public function getAlgorithmString() {
27        return $this->algorithm
28               . ($this->keyLength ? '-' . $this->keyLength : '')
29               . ($this->mode ? '-' . $this->mode : '');
30    }
31
32    public function generateIV() {
33        $this->iv = openssl_random_pseudo_bytes( openssl_cipher_iv_length( $this->getAlgorithmString() ) );
34    }
35
36    public function checkValidAlgorithm() {
37        $validAlgs = openssl_get_cipher_methods( true );
38        return in_array( $this->getAlgorithmString(), $validAlgs );
39    }
40}