Passed
Push — feature/post-pay ( 12bb6b...7e10da )
by Remco
04:44
created

Message::sign()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Message
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\OmniKassa2
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;
12
13
/**
14
 * Message
15
 *
16
 * @author  Remco Tolsma
17
 * @version 2.0.2
18
 * @since   2.0.2
19
 */
20
abstract class Message implements Signable {
21
	/**
22
	 * Signature.
23
	 *
24
	 * @var string
25
	 */
26
	private $signature;
27
28
	/**
29
	 * Get signature.
30
	 *
31
	 * @return string
32
	 */
33 5
	public function get_signature() {
34 5
		return $this->signature;
35
	}
36
37
	/**
38
	 * Set signature.
39
	 *
40
	 * @param string $signature Signature.
41
	 */
42 5
	protected function set_signature( $signature ) {
43 5
		$this->signature = $signature;
44 5
	}
45
46
	/**
47
	 * Sign this message with specified signing key.
48
	 *
49
	 * @param string $signing_key Signing key.
50
	 */
51
	public function sign( $signing_key ) {
52
		$signature = Security::get_signature( $this, $signing_key );
53
54
		$this->set_signature( $signature );
55
	}
56
57
	/**
58
	 * Check if this message is valid.
59
	 *
60
	 * @param string $signing_key Signing key.
61
	 * @return bool True if valid, false otherwise.
62
	 */
63 3
	public function is_valid( $signing_key ) {
64 3
		$signature = Security::get_signature( $this, $signing_key );
65
66 3
		if ( empty( $signature ) ) {
67
			return false;
68
		}
69
70 3
		return Security::validate_signature( $signature, $this->get_signature() );
71
	}
72
}
73