Update objects to use __toString()
This commit is contained in:
@@ -3,12 +3,11 @@
|
||||
use Leenooks\OpenPGP;
|
||||
|
||||
class MessageVerification extends PHPUnit\Framework\TestCase {
|
||||
public function oneMessageRSA($pkey, $path) {
|
||||
$pkeyM = OpenPGP\Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $pkey));
|
||||
$m = OpenPGP\Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path));
|
||||
$verify = new OpenPGP\Crypt\RSA($pkeyM);
|
||||
$this->assertSame($verify->verify($m), $m->signatures());
|
||||
}
|
||||
public function oneMessageRSA($pkey, $path) {
|
||||
$pkeyM = OpenPGP::load(file_get_contents(dirname(__FILE__).'/data/'.$pkey));
|
||||
$m = OpenPGP::load(file_get_contents(dirname(__FILE__).'/data/'.$path));
|
||||
$this->assertSame($pkeyM->verify($m->key()), $m->signatures());
|
||||
}
|
||||
|
||||
public function testUncompressedOpsRSA() {
|
||||
$this->oneMessageRSA('pubring.gpg', 'uncompressed-ops-rsa.gpg');
|
||||
@@ -26,14 +25,14 @@ class MessageVerification extends PHPUnit\Framework\TestCase {
|
||||
$this->oneMessageRSA('pubring.gpg', 'compressedsig-bzip2.gpg');
|
||||
}
|
||||
|
||||
public function testSigningMessages() {
|
||||
$wkey = OpenPGP\Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
|
||||
$data = new OpenPGP\LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
||||
$sign = new OpenPGP\Crypt\RSA($wkey);
|
||||
$m = $sign->sign($data)->to_bytes();
|
||||
$reparsedM = OpenPGP\Message::parse($m);
|
||||
$this->assertSame($sign->verify($reparsedM), $reparsedM->signatures());
|
||||
}
|
||||
public function testSigningMessages() {
|
||||
$wkey = OpenPGP\Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
|
||||
$data = new OpenPGP\LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
||||
$sign = new OpenPGP\Crypt\RSA($wkey);
|
||||
$m = (string)$sign->sign($data);
|
||||
$reparsedM = OpenPGP\Message::parse($m);
|
||||
$this->assertSame($sign->verify($reparsedM), $reparsedM->signatures());
|
||||
}
|
||||
|
||||
/*
|
||||
public function testUncompressedOpsDSA() {
|
||||
@@ -158,7 +157,7 @@ class Encryption extends PHPUnit\Framework\TestCase {
|
||||
public function oneSymmetric($algorithm) {
|
||||
$data = new OpenPGP\LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
||||
$encrypted = OpenPGP\Crypt\Symmetric::encrypt('secret', new OpenPGP\Message(array($data)), $algorithm);
|
||||
$encrypted = OpenPGP\Message::parse($encrypted->to_bytes());
|
||||
$encrypted = OpenPGP\Message::parse((string)$encrypted);
|
||||
$decrypted = OpenPGP\Crypt\Symmetric::decryptSymmetric('secret', $encrypted);
|
||||
$this->assertEquals($decrypted[0]->data, 'This is text.');
|
||||
}
|
||||
@@ -197,7 +196,7 @@ class Encryption extends PHPUnit\Framework\TestCase {
|
||||
$key = OpenPGP\Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
|
||||
$data = new OpenPGP\LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
||||
$encrypted = OpenPGP\Crypt\Symmetric::encrypt($key, new OpenPGP\Message(array($data)));
|
||||
$encrypted = OpenPGP\Message::parse($encrypted->to_bytes());
|
||||
$encrypted = OpenPGP\Message::parse((string)$encrypted);
|
||||
$decryptor = new OpenPGP\Crypt\RSA($key);
|
||||
$decrypted = $decryptor->decrypt($encrypted);
|
||||
$this->assertEquals($decrypted[0]->data, 'This is text.');
|
||||
|
@@ -3,12 +3,12 @@
|
||||
use Leenooks\OpenPGP;
|
||||
|
||||
class Serialization extends PHPUnit\Framework\TestCase {
|
||||
public function oneSerialization($path) {
|
||||
$in = OpenPGP\Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path));
|
||||
$mid = $in->to_bytes();
|
||||
$out = OpenPGP\Message::parse($mid);
|
||||
$this->assertEquals($in, $out);
|
||||
}
|
||||
public function oneSerialization($path) {
|
||||
$in = OpenPGP\Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path));
|
||||
$mid = (string)$in;
|
||||
$out = OpenPGP\Message::parse($mid);
|
||||
$this->assertEquals($in, $out);
|
||||
}
|
||||
|
||||
public function test000001006public_key() {
|
||||
$this->oneSerialization("000001-006.public_key");
|
||||
|
Reference in New Issue
Block a user