| @@ 197-205 (lines=9) @@ | ||
| 194 | * @param int $size Number of random bytes |
|
| 195 | * @return self |
|
| 196 | */ |
|
| 197 | public function withRandomSerialNumber($size = 16) { |
|
| 198 | // ensure that first byte is always non-zero and having first bit unset |
|
| 199 | $num = gmp_init(mt_rand(1, 0x7f), 10); |
|
| 200 | for ($i = 1; $i < $size; ++$i) { |
|
| 201 | $num <<= 8; |
|
| 202 | $num += mt_rand(0, 0xff); |
|
| 203 | } |
|
| 204 | return $this->withSerialNumber(gmp_strval($num, 10)); |
|
| 205 | } |
|
| 206 | ||
| 207 | /** |
|
| 208 | * Get self with validity period. |
|
| @@ 261-269 (lines=9) @@ | ||
| 258 | * @param int $size Number of random bytes |
|
| 259 | * @return self |
|
| 260 | */ |
|
| 261 | public function withRandomSerialNumber($size = 16) { |
|
| 262 | // ensure that first byte is always non-zero and having first bit unset |
|
| 263 | $num = gmp_init(mt_rand(1, 0x7f), 10); |
|
| 264 | for ($i = 1; $i < $size; ++$i) { |
|
| 265 | $num <<= 8; |
|
| 266 | $num += mt_rand(0, 0xff); |
|
| 267 | } |
|
| 268 | return $this->withSerialNumber(gmp_strval($num, 10)); |
|
| 269 | } |
|
| 270 | ||
| 271 | /** |
|
| 272 | * Get self with given signature algorithm. |
|