diff --git a/phpseclib/Crypt/Common/AsymmetricKey.php b/phpseclib/Crypt/Common/AsymmetricKey.php index 60ca9bb4..b2da0aa2 100644 --- a/phpseclib/Crypt/Common/AsymmetricKey.php +++ b/phpseclib/Crypt/Common/AsymmetricKey.php @@ -24,7 +24,7 @@ use phpseclib3\Crypt\DSA; use phpseclib3\Crypt\ECDSA; /** - * Base Class for all stream cipher classes + * Base Class for all asymmetric cipher classes * * @package AsymmetricKey * @author Jim Wigginton @@ -173,8 +173,8 @@ abstract class AsymmetricKey } $components['format'] = $format; - $new = static::onLoad($components); + $new->format = $format; return $new instanceof PrivateKey ? $new->withPassword($password) : $new; @@ -304,7 +304,7 @@ abstract class AsymmetricKey * Returns the format of the loaded key. * * If the key that was loaded wasn't in a valid or if the key was auto-generated - * with RSA::createKey() then this will return false. + * with RSA::createKey() then this will throw an exception. * * @see self::load() * @access public @@ -312,8 +312,8 @@ abstract class AsymmetricKey */ public function getLoadedFormat() { - if ($this->format === false) { - return false; + if (empty($this->format)) { + throw new NoKeyLoadedException('This key was created with createKey - it was not loaded with load. Therefore there is no "loaded format"'); } $meta = new \ReflectionClass($this->format); diff --git a/phpseclib/Crypt/DSA.php b/phpseclib/Crypt/DSA.php index ff62a290..71f32aae 100644 --- a/phpseclib/Crypt/DSA.php +++ b/phpseclib/Crypt/DSA.php @@ -95,7 +95,7 @@ abstract class DSA extends AsymmetricKey * @var string * @access private */ - protected $format; + protected $sigFormat; /** * Signature Format (Short) @@ -263,7 +263,7 @@ abstract class DSA extends AsymmetricKey */ protected function __construct() { - $this->format = self::validatePlugin('Signature', 'ASN1'); + $this->sigFormat = self::validatePlugin('Signature', 'ASN1'); $this->shortFormat = 'ASN1'; parent::__construct(); @@ -329,7 +329,7 @@ abstract class DSA extends AsymmetricKey { $new = clone $this; $new->shortFormat = $format; - $new->format = self::validatePlugin('Signature', $format); + $new->sigFormat = self::validatePlugin('Signature', $format); return $new; } diff --git a/phpseclib/Crypt/DSA/PrivateKey.php b/phpseclib/Crypt/DSA/PrivateKey.php index a8e70346..17e9ada3 100644 --- a/phpseclib/Crypt/DSA/PrivateKey.php +++ b/phpseclib/Crypt/DSA/PrivateKey.php @@ -85,7 +85,7 @@ class PrivateKey extends DSA implements Common\PrivateKey */ public function sign($message) { - $format = $this->format; + $format = $this->sigFormat; if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) { $signature = ''; diff --git a/phpseclib/Crypt/DSA/PublicKey.php b/phpseclib/Crypt/DSA/PublicKey.php index e352e905..b9741aa5 100644 --- a/phpseclib/Crypt/DSA/PublicKey.php +++ b/phpseclib/Crypt/DSA/PublicKey.php @@ -40,7 +40,7 @@ class PublicKey extends DSA implements Common\PublicKey */ public function verify($message, $signature) { - $format = $this->format; + $format = $this->sigFormat; $params = $format::load($signature); if ($params === false || count($params) != 2) { diff --git a/phpseclib/Crypt/EC.php b/phpseclib/Crypt/EC.php index 1576b4fe..af6b2a22 100644 --- a/phpseclib/Crypt/EC.php +++ b/phpseclib/Crypt/EC.php @@ -244,7 +244,7 @@ abstract class EC extends AsymmetricKey */ protected function __construct() { - $this->format = self::validatePlugin('Signature', 'ASN1'); + $this->sigFormat = self::validatePlugin('Signature', 'ASN1'); $this->shortFormat = 'ASN1'; parent::__construct(); @@ -383,7 +383,7 @@ abstract class EC extends AsymmetricKey $new = clone $this; $new->shortFormat = $format; - $new->format = self::validatePlugin('Signature', $format); + $new->sigFormat = self::validatePlugin('Signature', $format); return $new; } diff --git a/phpseclib/Crypt/EC/PrivateKey.php b/phpseclib/Crypt/EC/PrivateKey.php index 4ab15688..4ffa5fdf 100644 --- a/phpseclib/Crypt/EC/PrivateKey.php +++ b/phpseclib/Crypt/EC/PrivateKey.php @@ -100,7 +100,7 @@ class PrivateKey extends EC implements Common\PrivateKey $order = $this->curve->getOrder(); $shortFormat = $this->shortFormat; - $format = $this->format; + $format = $this->sigFormat; if ($format === false) { return false; } diff --git a/phpseclib/Crypt/EC/PublicKey.php b/phpseclib/Crypt/EC/PublicKey.php index ef749470..2cb92ab6 100644 --- a/phpseclib/Crypt/EC/PublicKey.php +++ b/phpseclib/Crypt/EC/PublicKey.php @@ -52,7 +52,7 @@ class PublicKey extends EC implements Common\PublicKey } $shortFormat = $this->shortFormat; - $format = $this->format; + $format = $this->sigFormat; if ($format === false) { return false; } diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index dd3c3e71..b1952028 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -407,7 +407,6 @@ abstract class RSA extends AsymmetricKey new PublicKey : new PrivateKey; - $key->format = $components['format']; $key->modulus = $components['modulus']; $key->publicExponent = $components['publicExponent']; $key->k = $key->modulus->getLengthInBytes();