Completed
Push — master ( d732f2...827150 )
by smiley
01:50
created

SignedMessage::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
/**
3
 * Class SignedMessage
4
 *
5
 * @filesource   SignedMessage.php
6
 * @created      25.01.2018
7
 * @package      chillerlan\Traits\Crypto
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2018 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Traits\Crypto;
14
15
class SignedMessage extends CryptoBox{
16
17
	public function create(string $message):CryptoBoxInterface{
18
		$this->checkKeypair(SODIUM_CRYPTO_SIGN_SECRETKEYBYTES);
19
20
		$this->box = sodium_crypto_sign($this->checkMessage($message), $this->keypair->secret);
0 ignored issues
show
Bug introduced by
Accessing secret on the interface chillerlan\Traits\Crypto\CryptoKeyInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
21
22
		sodium_memzero($message);
23
24
		return $this;
25
	}
26
27
	public function open(string $box_bin):CryptoBoxInterface{
28
		$this->checkKeypair(null, SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES);
29
30
		$this->message = sodium_crypto_sign_open($box_bin, $this->keypair->public);
0 ignored issues
show
Bug introduced by
Accessing public on the interface chillerlan\Traits\Crypto\CryptoKeyInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
31
32
		sodium_memzero($box_bin);
33
34
		return $this;
35
	}
36
37
}
38