1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-11-27 04:46:26 +01:00

- make it so setPublicKey() can guess at the format like loadKey() can

git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@204 21d32557-59b3-4da0-833f-c5933fad653e
This commit is contained in:
Jim Wigginton 2012-03-11 19:13:34 +00:00
parent 1b2dde6e7d
commit 60340d5466

View File

@ -1355,9 +1355,25 @@ class Crypt_RSA {
* @param Integer $type optional
* @return Boolean
*/
function setPublicKey($key, $type = CRYPT_RSA_PUBLIC_FORMAT_PKCS1)
function setPublicKey($key, $type = false)
{
$components = $this->_parseKey($key, $type);
if ($type === false) {
$types = array(
CRYPT_RSA_PUBLIC_FORMAT_RAW,
CRYPT_RSA_PUBLIC_FORMAT_PKCS1,
CRYPT_RSA_PUBLIC_FORMAT_XML,
CRYPT_RSA_PUBLIC_FORMAT_OPENSSH
);
foreach ($types as $type) {
$components = $this->_parseKey($key, $type);
if ($components !== false) {
break;
}
}
} else {
$components = $this->_parseKey($key, $type);
}
if (empty($this->modulus) || !$this->modulus->equals($components['modulus'])) {
user_error('Trying to load a public key? Use loadKey() instead. It\'s called loadKey() and not loadPrivateKey() for a reason.', E_USER_NOTICE);