/** * Returns an instance of the EncryptedKey Data Block * * @throws \Zend\InfoCard\XML\Exception * @return \Zend\InfoCard\XML\EncryptedKey */ public function getEncryptedKey() { $this->registerXPathNamespace('e', 'http://www.w3.org/2001/04/xmlenc#'); list($encryptedkey) = $this->xpath('//e:EncryptedKey'); if (!$encryptedkey instanceof \Zend\InfoCard\XML\AbstractElement) { throw new \Zend\InfoCard\XML\Exception\RuntimeException("Failed to retrieve encrypted key"); } return \Zend\InfoCard\XML\EncryptedKey::getInstance($encryptedkey); }
public function testEncryptedKeyThrowsExceptionOnGetEncryptionMethodWithBadXml() { $doc = file_get_contents(__DIR__ . "/_files/encryptedkey_missing_enc_algo.xml"); $ek = XML\EncryptedKey::getInstance($doc); $this->setExpectedException('Zend\InfoCard\XML\Exception\RuntimeException', 'Unable to determine the encryption algorithm in the'); $ek->getEncryptionMethod(); }
public function testEncryptedKeyErrors() { try { XML\EncryptedKey::getInstance(10); $this->fail("Expected Exception Not thrown"); } catch (\Exception $e) { /* yay */ } $doc = file_get_contents(dirname(__FILE__) . "/_files/encryptedkey_bad_block.xml"); try { XML\EncryptedKey::getInstance($doc); $this->fail("Expected Exception not thrown"); } catch (\Exception $e) { /* yay */ } $doc = file_get_contents(dirname(__FILE__) . "/_files/encryptedkey_missing_enc_algo.xml"); $ek = XML\EncryptedKey::getInstance($doc); try { $ek->getEncryptionMethod(); $this->fail("Expected Exception not thrown"); } catch (\Exception $e) { /* yay */ } }