4
4
5
5
namespace PHPSess \Encryption ;
6
6
7
- use PHPSess \Interfaces \ EncryptionInterface ;
7
+ use PHPSess \Exception \ UnableToEncryptException ;
8
8
use PHPSess \Exception \UnableToDecryptException ;
9
- use PHPSess \Exception \UnknownEncryptionAlgorithmException ;
10
- use PHPSess \Exception \ UnknownHashAlgorithmException ;
9
+ use PHPSess \Exception \UnableToHashException ;
10
+ use PHPSess \Interfaces \ EncryptionInterface ;
11
11
12
12
class OpenSSLEncryption implements EncryptionInterface
13
13
{
@@ -135,16 +135,18 @@ private function getEncryptionKey(string $sessionId): string
135
135
*
136
136
* To get a list of valid algorithms, see openssl_get_cipher_methods(true)
137
137
*
138
- * @throws UnknownEncryptionAlgorithmException
139
- * @param string $algorithm
138
+ * @throws UnableToEncryptException
139
+ * @param string $algorithm For a list of valid algorithm, see openssl_get_cipher_methods(true).
140
140
* @return void
141
141
*/
142
142
public function setEncryptionAlgorithm (string $ algorithm ): void
143
143
{
144
144
$ knownAlgorithms = openssl_get_cipher_methods (true );
145
145
146
146
if (!in_array ($ algorithm , $ knownAlgorithms )) {
147
- throw new UnknownEncryptionAlgorithmException ();
147
+ $ errorMessage = "The encryption algorithm \"$ algorithm \" is unknow. " .
148
+ 'For a list of valid algorithms, see openssl_get_cipher_methods(true). ' ;
149
+ throw new UnableToEncryptException ($ errorMessage );
148
150
}
149
151
150
152
$ this ->encryptionAlgorithm = $ algorithm ;
@@ -155,16 +157,18 @@ public function setEncryptionAlgorithm(string $algorithm): void
155
157
*
156
158
* To get a list of valid algorithms, see openssl_get_md_methods(true)
157
159
*
158
- * @throws UnknownHashAlgorithmException
159
- * @param string $algorithm
160
+ * @throws UnableToHashException
161
+ * @param string $algorithm For a list of valid algorithms, see openssl_get_md_methods(true).
160
162
* @return void
161
163
*/
162
164
public function setHashAlgorithm (string $ algorithm ): void
163
165
{
164
166
$ knownAlgorithms = openssl_get_md_methods (true );
165
167
166
168
if (!in_array ($ algorithm , $ knownAlgorithms )) {
167
- throw new UnknownHashAlgorithmException ();
169
+ $ errorMessage = "The hash algorithm \"$ algorithm \" is unknown. " .
170
+ 'For a list of valid algorithms, see openssl_get_md_methods(true). ' ;
171
+ throw new UnableToHashException ($ errorMessage );
168
172
}
169
173
170
174
$ this ->hashAlgorithm = $ algorithm ;
0 commit comments