From e255a5a5bd6f0ad2dea6cc0faaeebc9c5d68b548 Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 19 Oct 2015 09:00:17 -0400 Subject: [PATCH] Only one class per file (PSR-1) --- src/Key.php | 71 -------------------------------------------- src/KeyConfig.php | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 71 deletions(-) create mode 100644 src/KeyConfig.php diff --git a/src/Key.php b/src/Key.php index 3596261..227ff04 100644 --- a/src/Key.php +++ b/src/Key.php @@ -5,77 +5,6 @@ use \Defuse\Crypto\Core; use \Defuse\Crypto\Encoding; -final class KeyConfig -{ - private $key_byte_size; - private $checksum_hash_function; - private $checksum_byte_size; - - public function __construct($config_array) - { - $expected_keys = array( - "key_byte_size", - "checksum_hash_function", - "checksum_byte_size" - ); - if (sort($expected_keys) !== true) { - throw Ex\CannotPerformOperationException( - "sort() failed." - ); - } - - $actual_keys = array_keys($config_array); - if (sort($actual_keys) !== true) { - throw Ex\CannotPerformOperationException( - "sort() failed." - ); - } - - if ($expected_keys !== $actual_keys) { - throw new Ex\CannotPerformOperationException( - "Trying to instantiate a bad key configuration." - ); - } - - $this->key_byte_size = $config_array["key_byte_size"]; - $this->checksum_hash_function = $config_array["checksum_hash_function"]; - $this->checksum_byte_size = $config_array["checksum_byte_size"]; - - if (!\is_int($this->key_byte_size) || $this->key_byte_size <= 0) { - throw new Ex\CannotPerformOperationException( - "Invalid key byte size." - ); - } - - if (\in_array($this->checksum_hash_function, \hash_algos()) === false) { - throw new Ex\CannotPerformOperationException( - "Invalid hash function name." - ); - } - - if (!\is_int($this->checksum_byte_size) || $this->checksum_byte_size <= 0) { - throw new Ex\CannotPerformOperationException( - "Invalid checksum byte size." - ); - } - } - - public function keyByteSize() - { - return $this->key_byte_size; - } - - public function checksumHashFunction() - { - return $this->checksum_hash_function; - } - - public function checksumByteSize() - { - return $this->checksum_byte_size; - } -} - final class Key { /* We keep the key versioning independent of the ciphertext versioning. */ diff --git a/src/KeyConfig.php b/src/KeyConfig.php new file mode 100644 index 0000000..78d6c7d --- /dev/null +++ b/src/KeyConfig.php @@ -0,0 +1,75 @@ +key_byte_size = $config_array["key_byte_size"]; + $this->checksum_hash_function = $config_array["checksum_hash_function"]; + $this->checksum_byte_size = $config_array["checksum_byte_size"]; + + if (!\is_int($this->key_byte_size) || $this->key_byte_size <= 0) { + throw new Ex\CannotPerformOperationException( + "Invalid key byte size." + ); + } + + if (\in_array($this->checksum_hash_function, \hash_algos()) === false) { + throw new Ex\CannotPerformOperationException( + "Invalid hash function name." + ); + } + + if (!\is_int($this->checksum_byte_size) || $this->checksum_byte_size <= 0) { + throw new Ex\CannotPerformOperationException( + "Invalid checksum byte size." + ); + } + } + + public function keyByteSize() + { + return $this->key_byte_size; + } + + public function checksumHashFunction() + { + return $this->checksum_hash_function; + } + + public function checksumByteSize() + { + return $this->checksum_byte_size; + } +} \ No newline at end of file