diff --git a/.idea/deployment.xml b/.idea/deployment.xml
new file mode 100644
index 0000000..05f0e7d
--- /dev/null
+++ b/.idea/deployment.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/dictionaries/jonas.xml b/.idea/dictionaries/jonas.xml
new file mode 100644
index 0000000..84b414e
--- /dev/null
+++ b/.idea/dictionaries/jonas.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..28a804d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..4e6cb79
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,206 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1551357239839
+
+
+ 1551357239839
+
+
+
+ 1551357358782
+
+
+
+ 1551357358784
+
+
+ 1551359062114
+
+
+
+ 1551359062114
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/composer.json b/composer.json
index e1c2c92..cdab91b 100644
--- a/composer.json
+++ b/composer.json
@@ -16,9 +16,6 @@
"require-dev": {
"phpunit/phpunit": ">=4.0.0"
},
- "suggest": {
- "ext-mcrypt": "The mcrypt extension must be installed if /dev/urandom is not available."
- },
"autoload": {
"psr-4": { "CouponCode\\": "src/" }
}
diff --git a/src/CouponCode.php b/src/CouponCode.php
index ae0be45..ad8f634 100644
--- a/src/CouponCode.php
+++ b/src/CouponCode.php
@@ -233,22 +233,24 @@ protected function _normalize($string, array $options = []) {
return $string;
}
- /**
- * Generates a cryptographically secure sequence of bytes.
- *
- * @param integer $bytes Number of bytes to return.
- * @return string
- */
+ /**
+ * Generates a cryptographically secure sequence of bytes.
+ *
+ * @param integer $bytes Number of bytes to return.
+ * @return string
+ * @throws Exception
+ */
protected function _random($bytes) {
- if (is_readable('/dev/urandom')) {
- $stream = fopen('/dev/urandom', 'rb');
- $result = fread($stream, $bytes);
+ //if (is_readable('/dev/urandom')) {
+ if ($fh = @fopen('/dev/urandom', 'rb')) {
+ $stream = fopen('/dev/urandom', 'rb');
+ $result = fread($stream, $bytes);
- fclose($stream);
- return $result;
- }
- if (function_exists('mcrypt_create_iv')) {
- return mcrypt_create_iv($bytes, MCRYPT_DEV_RANDOM);
+ fclose($stream);
+ return $result;
+ }
+ if (function_exists('random_bytes')) {
+ return random_bytes($bytes);
}
throw new Exception("No source for generating a cryptographically secure seed found.");
}