Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Authenticated_Nonce | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
20 | |||
| verify | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack\Packages\Async_Option; |
| 4 | |
| 5 | class Authenticated_Nonce { |
| 6 | |
| 7 | /** |
| 8 | * @var string Nonce key |
| 9 | */ |
| 10 | private $key; |
| 11 | |
| 12 | public function __construct( $key ) { |
| 13 | $this->key = $key; |
| 14 | } |
| 15 | |
| 16 | public function create() { |
| 17 | |
| 18 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! did_action( 'set_current_user' ) ) { |
| 19 | throw new \Exception( "Debug: Attempting to create {$this->key} nonce before the user is set." ); |
| 20 | } |
| 21 | return wp_create_nonce( $this->key ); |
| 22 | } |
| 23 | |
| 24 | public function verify( $nonce ) { |
| 25 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! did_action( 'set_current_user' ) ) { |
| 26 | throw new \Exception( "Debug: Attempting to validate {$this->key} nonce before the user is set." ); |
| 27 | } |
| 28 | |
| 29 | return wp_verify_nonce( $nonce, $this->key ); |
| 30 | } |
| 31 | } |