[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / Keypair.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * This class contain an RSA key pair. Its purpose is to keep to keys
19 * and transfer these keys between other PHP classes.
20 *
21 * @author Dmitry Dulepov <dmitry@typo3.org>
22 */
23 class Keypair implements \TYPO3\CMS\Core\SingletonInterface {
24 /**
25 * RSA public exponent (3 or 0x10001)
26 *
27 * @var integer
28 */
29 protected $exponent = 0;
30
31 /**
32 * The private key
33 *
34 * @var string
35 */
36 protected $privateKey = '';
37
38 /**
39 * The public key modulus
40 *
41 * @var integer
42 */
43 protected $publicKeyModulus = 0;
44
45 /**
46 * Checks if this key pair already has been provided with all data.
47 *
48 * @return boolean
49 */
50 public function isReady() {
51 return $this->hasExponent() && $this->hasPrivateKey() && $this->hasPublicKeyModulus();
52 }
53
54 /**
55 * Retrieves the exponent.
56 *
57 * @return integer the exponent
58 */
59 public function getExponent() {
60 return $this->exponent;
61 }
62
63 /**
64 * Sets the exponent
65 *
66 * Note: This method must not be called more than one time.
67 *
68 * @param integer $exponent the new exponent
69 *
70 * @return void
71 *
72 * @throws \BadMethodCallException if the method was called more than one time
73 */
74 public function setExponent($exponent) {
75 if ($this->hasExponent()) {
76 throw new \BadMethodCallException('setExponent() must not be called more than one time.', 1296062830);
77 }
78
79 $this->exponent = $exponent;
80 }
81
82 /**
83 * Checks whether an exponent already has been set.
84 *
85 * @return boolean
86 */
87 protected function hasExponent() {
88 return $this->getExponent() !== 0;
89 }
90
91 /**
92 * Retrieves the private key.
93 *
94 * @return string The private key
95 */
96 public function getPrivateKey() {
97 return $this->privateKey;
98 }
99
100 /**
101 * Sets the private key.
102 *
103 * Note: This method must not be called more than one time.
104 *
105 * @param string $privateKey The new private key
106 *
107 * @return void
108 *
109 * @throws \BadMethodCallException if the method was called more than one time
110 */
111 public function setPrivateKey($privateKey) {
112 if ($this->hasPrivateKey()) {
113 throw new \BadMethodCallException('setPrivateKey() must not be called more than one time.', 1296062831);
114 }
115
116 $this->privateKey = $privateKey;
117 }
118
119 /**
120 * Checks whether a private key already has been set.
121 *
122 * @return boolean
123 */
124 protected function hasPrivateKey() {
125 return $this->getPrivateKey() !== '';
126 }
127
128 /**
129 * Retrieves the public key modulus
130 *
131 * @return integer the public key modulus
132 */
133 public function getPublicKeyModulus() {
134 return $this->publicKeyModulus;
135 }
136
137 /**
138 * Sets the public key modulus.
139 *
140 * Note: This method must not be called more than one time.
141 *
142 * @param integer $publicKeyModulus the new public key modulus
143 *
144 * @return void
145 *
146 * @throws \BadMethodCallException if the method was called more than one time
147 */
148 public function setPublicKey($publicKeyModulus) {
149 if ($this->hasPublicKeyModulus()) {
150 throw new \BadMethodCallException('setPublicKey() must not be called more than one time.', 1296062832);
151 }
152
153 $this->publicKeyModulus = $publicKeyModulus;
154 }
155
156 /**
157 * Checks whether a public key modulus already has been set.
158 *
159 * @return boolean
160 */
161 protected function hasPublicKeyModulus() {
162 return $this->getPublicKeyModulus() !== 0;
163 }
164 }