Skip to content

Commit 803cec9

Browse files
authored
Bump to PHP 8.2 and leverage its new features (#66)
* Add ext-random to list of direct dependencies and use the new 8.2 exception * Use new openssl builtin to replace constants
1 parent f99737b commit 803cec9

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

src/Backend/OpenSSL.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use function chr;
1616
use function mb_strlen;
1717
use function openssl_cipher_iv_length;
18+
use function openssl_cipher_key_length;
1819
use function openssl_decrypt;
1920
use function openssl_encrypt;
2021
use function openssl_sign;
@@ -252,7 +253,7 @@ public function setCipher(string $cipher): void
252253
default:
253254
$this->cipher = C::$BLOCK_CIPHER_ALGORITHMS[$cipher];
254255
$this->blocksize = C::$BLOCK_SIZES[$cipher];
255-
$this->keysize = C::$BLOCK_CIPHER_KEY_SIZES[$cipher];
256+
$this->keysize = openssl_cipher_key_length(C::$BLOCK_CIPHER_ALGORITHMS[$cipher]);
256257
}
257258
}
258259

src/Constants.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,6 @@ class Constants extends \SimpleSAML\XML\Constants
217217
self::BLOCK_ENC_AES256_GCM => 16,
218218
];
219219

220-
/** @var array<string, positive-int> */
221-
public static array $BLOCK_CIPHER_KEY_SIZES = [
222-
self::BLOCK_ENC_3DES => 24,
223-
self::BLOCK_ENC_AES128 => 16,
224-
self::BLOCK_ENC_AES192 => 24,
225-
self::BLOCK_ENC_AES256 => 32,
226-
self::BLOCK_ENC_AES128_GCM => 16,
227-
self::BLOCK_ENC_AES192_GCM => 24,
228-
self::BLOCK_ENC_AES256_GCM => 32,
229-
];
230-
231220
/** @var array<string, string> */
232221
public static array $RSA_DIGESTS = [
233222
self::SIG_RSA_SHA1 => self::DIGEST_SHA1,
@@ -261,7 +250,7 @@ class Constants extends \SimpleSAML\XML\Constants
261250
self::C14N_INCLUSIVE_WITHOUT_COMMENTS,
262251
self::C14N_EXCLUSIVE_WITH_COMMENTS,
263252
self::C14N_EXCLUSIVE_WITHOUT_COMMENTS,
264-
// self::C14N11_INCLUSIVE_WITH_COMMENTS,
265-
// self::C14N11_INCLUSIVE_WITHOUT_COMMENTS,
253+
self::C14N11_INCLUSIVE_WITH_COMMENTS,
254+
self::C14N11_INCLUSIVE_WITHOUT_COMMENTS,
266255
];
267256
}

src/Utils/Random.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleSAML\XMLSecurity\Utils;
66

7-
use Exception;
7+
use Random\RandomException;
88
use SimpleSAML\Assert\Assert;
99
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
1010
use SimpleSAML\XMLSecurity\Exception\RuntimeException;
@@ -43,7 +43,7 @@ public static function generateRandomBytes(int $length): string
4343
return random_bytes($length);
4444
} catch (ValueError) { // @phpstan-ignore-line
4545
throw new InvalidArgumentException('Invalid length received to generate random bytes.');
46-
} catch (Exception) {
46+
} catch (RandomException) {
4747
throw new RuntimeException(
4848
'Cannot generate random bytes, no cryptographically secure random generator available.',
4949
);

0 commit comments

Comments
 (0)