set password in load methods for each pubkey instead of in loader

This commit is contained in:
terrafrost 2019-06-28 08:58:20 -05:00
parent 5573187f3d
commit eb659a5544
2 changed files with 16 additions and 20 deletions

View File

@ -171,7 +171,10 @@ abstract class AsymmetricKey
$components['format'] = $format;
return static::onLoad($components);
$new = static::onLoad($components);
return $new instanceof PrivateKey ?
$new->withPassword($password) :
$new;
}
/**
@ -199,7 +202,10 @@ abstract class AsymmetricKey
$components['format'] = $format;
return static::onLoad($components);
$new = static::onLoad($components);
return $new instanceof PrivateKey ?
$new->withPassword($password) :
$new;
}
/**

View File

@ -39,26 +39,16 @@ abstract class PublicKeyLoader
public static function load($key, $password = false)
{
try {
$new = EC::load($key, $password);
} catch (\Exception $e) {}
return EC::load($key, $password);
} catch (NoKeyLoadedException $e) {}
if (!isset($new)) {
try {
$new = RSA::load($key, $password);
} catch (\Exception $e) {}
}
try {
return RSA::load($key, $password);
} catch (NoKeyLoadedException $e) {}
if (!isset($new)) {
try {
$new = DSA::load($key, $password);
} catch (\Exception $e) {}
}
if (isset($new)) {
return $new instanceof PrivateKey ?
$new->withPassword($password) :
$new;
}
try {
return DSA::load($key, $password);
} catch (NoKeyLoadedException $e) {}
try {
$x509 = new X509();