Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions src/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
75 changes: 75 additions & 0 deletions src/KeyConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
namespace Defuse\Crypto;

use \Defuse\Crypto\Exception as Ex;

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;
}
}