From 995a9d784047dd6ffb9593ad4280ee6f30ea68db Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 20 Jan 2013 17:51:37 -0500 Subject: [PATCH] Fingerprint tests --- lib/openpgp.php | 4 ++-- phpunit.xml | 4 ++++ tests/suite.php | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/openpgp.php b/lib/openpgp.php index 4537798..04a1009 100644 --- a/lib/openpgp.php +++ b/lib/openpgp.php @@ -1193,9 +1193,9 @@ class OpenPGP_PublicKeyPacket extends OpenPGP_Packet { switch ($this->version) { case 2: case 3: - return $this->fingerprint = md5(implode('', $this->fingerprint_material())); + return $this->fingerprint = strtoupper(md5(implode('', $this->fingerprint_material()))); case 4: - return $this->fingerprint = sha1(implode('', $this->fingerprint_material())); + return $this->fingerprint = strtoupper(sha1(implode('', $this->fingerprint_material()))); } } diff --git a/phpunit.xml b/phpunit.xml index 375bb57..00cfad3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,5 +3,9 @@ tests/suite.php + + + tests/suite.php + diff --git a/tests/suite.php b/tests/suite.php index 6391215..1fabf72 100644 --- a/tests/suite.php +++ b/tests/suite.php @@ -367,3 +367,26 @@ class Serialization extends PHPUnit_Framework_TestCase { $this->oneSerialization("uncompressed-ops-rsa.gpg"); } } + +class Fingerprint extends PHPUnit_Framework_TestCase { + public function oneFingerprint($path, $kf) { + $m = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path)); + $this->assertEquals($m[0]->fingerprint(), $kf); + } + + public function test000001006public_key() { + $this->oneFingerprint("000001-006.public_key", "421F28FEAAD222F856C8FFD5D4D54EA16F87040E"); + } + + public function test000016006public_key() { + $this->oneFingerprint("000016-006.public_key", "AF95E4D7BAC521EE9740BED75E9F1523413262DC"); + } + + public function test000027006public_key() { + $this->oneFingerprint("000027-006.public_key", "1EB20B2F5A5CC3BEAFD6E5CB7732CF988A63EA86"); + } + + public function test000035006public_key() { + $this->oneFingerprint("000035-006.public_key", "CB7933459F59C70DF1C3FBEEDEDC3ECF689AF56D"); + } +}