| @@ 194-202 (lines=9) @@ | ||
| 191 | * @param int $size Number of random bytes |
|
| 192 | * @return self |
|
| 193 | */ |
|
| 194 | public function withRandomSerialNumber($size = 16) { |
|
| 195 | // ensure that first byte is always non-zero and having first bit unset |
|
| 196 | $num = gmp_init(mt_rand(1, 0x7f), 10); |
|
| 197 | for ($i = 1; $i < $size; ++$i) { |
|
| 198 | $num <<= 8; |
|
| 199 | $num += mt_rand(0, 0xff); |
|
| 200 | } |
|
| 201 | return $this->withSerialNumber(gmp_strval($num, 10)); |
|
| 202 | } |
|
| 203 | ||
| 204 | /** |
|
| 205 | * Get self with validity period. |
|
| @@ 250-258 (lines=9) @@ | ||
| 247 | * @param int $size Number of random bytes |
|
| 248 | * @return self |
|
| 249 | */ |
|
| 250 | public function withRandomSerialNumber($size = 16) { |
|
| 251 | // ensure that first byte is always non-zero and having first bit unset |
|
| 252 | $num = gmp_init(mt_rand(1, 0x7f), 10); |
|
| 253 | for ($i = 1; $i < $size; ++$i) { |
|
| 254 | $num <<= 8; |
|
| 255 | $num += mt_rand(0, 0xff); |
|
| 256 | } |
|
| 257 | return $this->withSerialNumber(gmp_strval($num, 10)); |
|
| 258 | } |
|
| 259 | ||
| 260 | /** |
|
| 261 | * Get self with given signature algorithm. |
|