/** * @test * * @expectedException \InvalidArgumentException * * @uses \Lcobucci\JWT\Signer\Ecdsa\KeyParser::__construct * @uses \Lcobucci\JWT\Signer\Key * * @covers \Lcobucci\JWT\Signer\Ecdsa\KeyParser::getPrivateKey * @covers \Lcobucci\JWT\Signer\Ecdsa\KeyParser::getKeyContent */ public function getPrivateKeyShouldRaiseExceptionWhenAWrongKeyWasGiven() { $this->privateKeySerializer->expects($this->never())->method('parse'); $parser = new KeyParser($this->privateKeySerializer, $this->publicKeySerializer); $parser->getPrivateKey($this->getPublicKey()); }
/** * Parses a private key from the given PEM content * * @param Key $key * * @return \Mdanter\Ecc\Crypto\Key\PrivateKeyInterface */ public function getPrivateKey(Key $key) { return $this->privateKeySerializer->parse($this->getKeyContent($key, 'EC PRIVATE KEY')); }
/** * @param string $key * @param PrivateKeySerializerInterface|PublicKeySerializerInterface $serializer * @return PrivateKeyInterface|PublicKeyInterface * @throws \Exception */ private function deserialize($key, $serializer) { try { return $serializer->parse($key); } catch (\Exception $e) { throw new \Exception('Invalid key.'); } }