1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* The key exchange information data object. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace CryptoManana\DataStructures; |
8
|
|
|
|
9
|
|
|
use \CryptoManana\Core\Abstractions\DataStructures\AbstractBasicStructure as BasicDataStructure; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ExchangeInformation - The key exchange information data object. |
13
|
|
|
* |
14
|
|
|
* @package CryptoManana\DataStructures |
15
|
|
|
* |
16
|
|
|
* @property string $prime The hexadecimal representation of a prime number, also knows as `p`. |
17
|
|
|
* @property string $generator The hexadecimal generator number, a primitive root modulo of `p`, also known as `g`. |
18
|
|
|
* @property string $private The private key. |
19
|
|
|
* @property string $public The public key. |
20
|
|
|
*/ |
21
|
|
|
class ExchangeInformation extends BasicDataStructure |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The prime number property storage. |
25
|
|
|
* |
26
|
|
|
* @var string The chosen prime number, also knows as `p` |
27
|
|
|
*/ |
28
|
|
|
protected $prime = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The generator number property storage. |
32
|
|
|
* |
33
|
|
|
* @var string The chosen generator number, also knows as `g` |
34
|
|
|
*/ |
35
|
|
|
protected $generator = ''; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The private key property storage. |
39
|
|
|
* |
40
|
|
|
* @var string The private key. |
41
|
|
|
*/ |
42
|
|
|
protected $private = ''; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The public key property storage. |
46
|
|
|
* |
47
|
|
|
* @var string The public key. |
48
|
|
|
*/ |
49
|
|
|
protected $public = ''; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Exchange information constructor. |
53
|
|
|
* |
54
|
|
|
* @param string $prime The hexadecimal representation of a prime number, also knows as `p`. |
55
|
|
|
* @param string $generator The hexadecimal generator number, a primitive root modulo of `p`, also known as `g`. |
56
|
|
|
* @param string $privateKey The private key. |
57
|
|
|
* @param string $publicKey The public key. |
58
|
|
|
*/ |
59
|
|
|
public function __construct($prime = '', $generator = '', $privateKey = '', $publicKey = '') |
60
|
|
|
{ |
61
|
|
|
if (is_string($prime)) { |
|
|
|
|
62
|
|
|
$this->prime = $prime; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (is_string($generator)) { |
|
|
|
|
66
|
|
|
$this->generator = $generator; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (is_string($privateKey)) { |
|
|
|
|
70
|
|
|
$this->private = $privateKey; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (is_string($publicKey)) { |
|
|
|
|
74
|
|
|
$this->public = $publicKey; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Exchange information destructor |
80
|
|
|
*/ |
81
|
|
|
public function __destruct() |
82
|
|
|
{ |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* The key exchange information data string representation. |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function __toString() |
91
|
|
|
{ |
92
|
|
|
return 'prime : ' . $this->prime . |
93
|
|
|
' | generator : ' . $this->generator . |
94
|
|
|
' | private : ' . $this->private . |
95
|
|
|
' | public : ' . $this->public; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|