Пример #1
0
 protected function assertSignatureEquals(Crypt_GPG_Signature $expected, Crypt_GPG_Signature $actual)
 {
     $expectedUserId = $expected->getUserId();
     $actualUserId = $actual->getUserId();
     $this->assertEquals($expectedUserId, $actualUserId, 'Signature user ids do not match.');
     $expectedId = $expected->getId();
     $actualId = $actual->getId();
     $this->assertEquals(strlen($expectedId), strlen($actualId), 'Signature IDs are of different length.');
     $this->assertEquals($expected->getKeyFingerprint(), $actual->getKeyFingerprint(), 'Signature key fingerprints do not match.');
     $this->assertEquals($expected->getKeyId(), $actual->getKeyId(), 'Signature key IDs do not match.');
     $this->assertEquals($expected->getCreationDate(), $actual->getCreationDate(), 'Signature creation dates do not match.');
     $this->assertEquals($expected->getExpirationDate(), $actual->getExpirationDate(), 'Signature expiration dates do not match.');
     $this->assertEquals($expected->isValid(), $actual->isValid(), 'Signature validity does match.');
 }
Пример #2
0
 /**
  * @group accessors
  */
 public function testIsValid()
 {
     $signature = new Crypt_GPG_Signature(array('id' => 'KuhELanvhPRXozEjFWb2mam1q20', 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', 'creation' => 1221785858, 'expiration' => 1421785858, 'valid' => true, 'userId' => 'Alice <*****@*****.**>'));
     $this->assertTrue($signature->isValid());
     $signature = new Crypt_GPG_Signature(array('id' => 'KuhELanvhPRXozEjFWb2mam1q20', 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', 'creation' => 1221785858, 'expiration' => 1421785858, 'valid' => false, 'userId' => 'Alice <*****@*****.**>'));
     $this->assertFalse($signature->isValid());
 }
Пример #3
0
 /**
  * Verify a message
  *
  * @param Message $message
  * @param string $fingerprint
  * @return bool
  * @throws \Exception
  */
 public function verify(Message $message, string $fingerprint) : bool
 {
     $gnupg = new \Crypt_GPG($this->options);
     $gnupg->addSignKey($fingerprint);
     /**
      * @var \Crypt_GPG_Signature[]
      */
     $verified = $gnupg->verify($message->getBodyText());
     foreach ($verified as $sig) {
         if (false) {
             $sig = new \Crypt_GPG_Signature();
         }
         if ($sig->isValid()) {
             return true;
         }
     }
     return false;
 }