*
* The MIT License (MIT)
*
- * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
+ * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
function random_bytes($bytes)
{
try {
+ /** @var int $bytes */
$bytes = RandomCompat_intval($bytes);
} catch (TypeError $ex) {
throw new TypeError(
);
}
+ /** @var string $buf */
$buf = '';
if (!class_exists('COM')) {
throw new Error(
'COM does not exist'
);
}
+ /** @var COM $util */
$util = new COM('CAPICOM.Utilities.1');
$execCount = 0;
* get N bytes of random data, then CAPICOM has failed us.
*/
do {
- $buf .= base64_decode($util->GetRandom($bytes, 0));
+ $buf .= base64_decode((string) $util->GetRandom($bytes, 0));
if (RandomCompat_strlen($buf) >= $bytes) {
/**
* Return our random entropy buffer here:
*/
- return RandomCompat_substr($buf, 0, $bytes);
+ return (string) RandomCompat_substr($buf, 0, $bytes);
}
++$execCount;
} while ($execCount < $bytes);