/** * @depends testNonceSize */ public function testNonceFastForward() { $this->assertTrue(Helpers::nonceCheck(Helpers::hex2bin($this->nonceData['new']), Helpers::hex2bin($this->nonceData['old'])) === 'MSG_FAST_FORWARD'); }
/** * @requires extension libsodium */ public function testBinaryConversion() { $this->assertTrue(Helpers::bin2hex(Helpers::hex2bin('a1b2c3d4f5')) === 'a1b2c3d4f5'); }
/** * @param string $message * @param string $signature * @param string $signer_public * @return bool * @throws SignatureException * @throws InvalidTypeException */ public static function verify($message, $signature, $signer_public) { # Test to make sure all the required variables are strings. Helpers::isString($message, 'PublicKeyEncryption', 'verify'); Helpers::isString($signature, 'PublicKeyEncryption', 'verify'); Helpers::isString($signer_public, 'PublicKeyEncryption', 'verify'); # Decode the signature from hex $signature = base64_decode(Helpers::hex2bin($signature)); # Decode the signer's public key from hex $signer_public = Helpers::hex2bin($signer_public); if (\Sodium\crypto_sign_verify_detached($signature, $message, $signer_public)) { return true; } else { throw new SignatureException('Signature for message invalid.'); } }