Skip to content

Commit

Permalink
Merge pull request #31 from paragonie/fix-psalm
Browse files Browse the repository at this point in the history
Attempt to fix Psalm tests for PHP 7.4
  • Loading branch information
paragonie-security authored Jun 27, 2020
2 parents e74270b + e318cfb commit 9f2a6c3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ matrix:

install:
- composer self-update
- if [[ $USE_PSALM -eq 1 ]]; then composer require --dev "vimeo/psalm:^1|^2"; fi
- if [[ $USE_PSALM -eq 1 ]]; then composer require --dev "vimeo/psalm:^1|^3"; fi
- composer update

script:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"require-dev": {
"composer/composer": "^1",
"phpunit/phpunit": "^4|^5|^6"
"phpunit/phpunit": "^4|^5|^6|^7"
},
"scripts": {
"post-autoload-dump": [
Expand Down
3 changes: 3 additions & 0 deletions src/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function __construct(
$this->signature = $signature;
$this->chronicleHash = $chronicleHash;
if (!empty($customValidator)) {
/** @psalm-suppress MixedMethodCall */
if (\class_exists($customValidator)) {
$newClass = new $customValidator();
if (!($newClass instanceof Validator)) {
Expand Down Expand Up @@ -177,6 +178,8 @@ public function getChronicleHash()
*
* @return Validator
* @throws CertaintyException
*
* @psalm-suppress DocblockTypeContradiction
*/
public function getValidator()
{
Expand Down
13 changes: 9 additions & 4 deletions src/LocalCACertBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ParagonIE\Certainty\Exception\FilesystemException;
use ParagonIE\Certainty\Exception\InvalidResponseException;
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\ConstantTime\Binary;
use ParagonIE\ConstantTime\Hex;

/**
Expand Down Expand Up @@ -226,6 +227,8 @@ public function getPublicKey($raw = false)
* @return bool
* @throws CertaintyException
* @throws \SodiumException
*
* @psalm-suppress RedundantConditionGivenDocblockType
*/
public function save()
{
Expand Down Expand Up @@ -311,9 +314,9 @@ public function setChronicle(
$clientId = '',
$repository = 'paragonie/certainty'
) {
if (\ParagonIE_Sodium_Core_Util::strlen($publicKey) === 64) {
if (Binary::safeStrlen($publicKey) === 64) {
$publicKey = Hex::decode($publicKey);
} elseif (\ParagonIE_Sodium_Core_Util::strlen($publicKey) !== 32) {
} elseif (Binary::safeStrlen($publicKey) !== 32) {
throw new CryptoException(
'Signing secret keys must be SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES bytes long.'
);
Expand All @@ -332,6 +335,8 @@ public function setChronicle(
* @param string $string
* @return self
* @throws \TypeError
*
* @psalm-suppress MixedMethodCall
*/
public function setCustomValidator($string = '')
{
Expand Down Expand Up @@ -381,9 +386,9 @@ public function setOutputJsonFile($string = '')
public function setSigningKey($secretKey = '')
{
// Handle hex-encoded strings.
if (\ParagonIE_Sodium_Core_Util::strlen($secretKey) === 128) {
if (Binary::safeStrlen($secretKey) === 128) {
$secretKey = Hex::decode($secretKey);
} elseif (\ParagonIE_Sodium_Core_Util::strlen($secretKey) !== 64) {
} elseif (Binary::safeStrlen($secretKey) !== 64) {
throw new CryptoException(
'Signing secret keys must be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes long.'
);
Expand Down
2 changes: 1 addition & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function checkChronicleHash(Bundle $bundle)
$ok = false;
}
if (!$ok) {
if (self::THROW_MORE_EXCEPTIONS) {
if (static::THROW_MORE_EXCEPTIONS) {
if (isset($json['error'])) {
/** @var string $jsonError */
$jsonError = $json['error'];
Expand Down

0 comments on commit 9f2a6c3

Please sign in to comment.