Skip to content

Commit 7e120a0

Browse files
committed
Make validateSignature() behave more intuitively
1 parent 126c396 commit 7e120a0

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

phpseclib/File/X509.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,9 +1809,7 @@ function validateDate($date = NULL)
18091809
* Validate a signature
18101810
*
18111811
* Works on X.509 certs, CSR's and CRL's.
1812-
* Returns 1 if the signature is verified, 0 if it is not correct or -1 on error
1813-
*
1814-
* To know if a signature is valid one should do validateSignature() === 1
1812+
* Returns true if the signature is verified, false if it is not correct or NULL on error
18151813
*
18161814
* The behavior of this function is inspired by {@link http://php.net/openssl-verify openssl_verify}.
18171815
*
@@ -1861,10 +1859,10 @@ function validateSignature($options = 0)
18611859
}
18621860
}
18631861
if (count($this->CAs) == $i && ($options & FILE_X509_VALIDATE_SIGNATURE_BY_CA)) {
1864-
return 0;
1862+
return false;
18651863
}
18661864
} elseif (!isset($signingCert) || ($options & FILE_X509_VALIDATE_SIGNATURE_BY_CA)) {
1867-
return 0;
1865+
return false;
18681866
}
18691867
return $this->_validateSignature(
18701868
$signingCert['tbsCertificate']['subjectPublicKeyInfo']['algorithm']['algorithm'],
@@ -1898,7 +1896,7 @@ function validateSignature($options = 0)
18981896
}
18991897
}
19001898
if (!isset($signingCert)) {
1901-
return 0;
1899+
return false;
19021900
}
19031901
return $this->_validateSignature(
19041902
$signingCert['tbsCertificate']['subjectPublicKeyInfo']['algorithm']['algorithm'],
@@ -1908,14 +1906,14 @@ function validateSignature($options = 0)
19081906
$this->signatureSubject
19091907
);
19101908
default:
1911-
return 0;
1909+
return false;
19121910
}
19131911
}
19141912

19151913
/**
19161914
* Validates a signature
19171915
*
1918-
* Returns 1 if the signature is verified, 0 if it is not correct or -1 on error
1916+
* Returns true if the signature is verified, false if it is not correct or NULL on error
19191917
*
19201918
* @param String $publicKeyAlgorithm
19211919
* @param String $publicKey
@@ -1947,18 +1945,18 @@ function _validateSignature($publicKeyAlgorithm, $publicKey, $signatureAlgorithm
19471945
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
19481946

19491947
if (!@$rsa->verify($signatureSubject, $signature)) {
1950-
return 0;
1948+
return false;
19511949
}
19521950
break;
19531951
default:
1954-
return -1;
1952+
return NULL;
19551953
}
19561954
break;
19571955
default:
1958-
return -1;
1956+
return NULL;
19591957
}
19601958

1961-
return 1;
1959+
return true;
19621960
}
19631961

19641962
/**

0 commit comments

Comments
 (0)