44
55namespace PHPSess \Encryption ;
66
7- use PHPSess \Interfaces \ EncryptionInterface ;
7+ use PHPSess \Exception \ UnableToEncryptException ;
88use PHPSess \Exception \UnableToDecryptException ;
9- use PHPSess \Exception \UnknownEncryptionAlgorithmException ;
10- use PHPSess \Exception \ UnknownHashAlgorithmException ;
9+ use PHPSess \Exception \UnableToHashException ;
10+ use PHPSess \Interfaces \ EncryptionInterface ;
1111
1212class OpenSSLEncryption implements EncryptionInterface
1313{
@@ -135,16 +135,18 @@ private function getEncryptionKey(string $sessionId): string
135135 *
136136 * To get a list of valid algorithms, see openssl_get_cipher_methods(true)
137137 *
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).
140140 * @return void
141141 */
142142 public function setEncryptionAlgorithm (string $ algorithm ): void
143143 {
144144 $ knownAlgorithms = openssl_get_cipher_methods (true );
145145
146146 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 );
148150 }
149151
150152 $ this ->encryptionAlgorithm = $ algorithm ;
@@ -155,16 +157,18 @@ public function setEncryptionAlgorithm(string $algorithm): void
155157 *
156158 * To get a list of valid algorithms, see openssl_get_md_methods(true)
157159 *
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).
160162 * @return void
161163 */
162164 public function setHashAlgorithm (string $ algorithm ): void
163165 {
164166 $ knownAlgorithms = openssl_get_md_methods (true );
165167
166168 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 );
168172 }
169173
170174 $ this ->hashAlgorithm = $ algorithm ;
0 commit comments