| @@ 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. |
|
| @@ 202-210 (lines=9) @@ | ||
| 199 | * @param int $size Number of random bytes |
|
| 200 | * @return self |
|
| 201 | */ |
|
| 202 | public function withRandomSerialNumber($size = 16) { |
|
| 203 | // ensure that first byte is always non-zero and having first bit unset |
|
| 204 | $num = gmp_init(mt_rand(1, 0x7f), 10); |
|
| 205 | for ($i = 1; $i < $size; ++$i) { |
|
| 206 | $num <<= 8; |
|
| 207 | $num += mt_rand(0, 0xff); |
|
| 208 | } |
|
| 209 | return $this->withSerialNumber(gmp_strval($num, 10)); |
|
| 210 | } |
|
| 211 | ||
| 212 | /** |
|
| 213 | * Get self with validity period. |
|