Skip to content

Commit

Permalink
Merge pull request #21 from AngryBytes/feat/php81
Browse files Browse the repository at this point in the history
PHP 8.1 support, dependency upgrades
  • Loading branch information
t0mmie authored Dec 21, 2021
2 parents 6bff493 + a6c6bd0 commit 942ff89
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 431 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/php-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ jobs:
composer-check:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.3', '7.4', '8.0']
php-versions: ['7.4', '8.0', '8.1']
name: PHP ${{ matrix.php-versions }} tests
steps:
- name: Checkout
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 4.0.0

## PHP Support

The minimum supported PHP version is now 7.4.

Support was added for PHP 8.1

## 3.0.0

## PHP Support
Expand Down
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@
"license": "MIT",
"autoload": {
"psr-0": {
"AngryBytes\\Hash": "src"
"AngryBytes\\Hash": "src/",
"AngryBytes\\Hash\\Test": "tests/"
}
},
"scripts": {
"phpcheck": [
"./vendor/bin/phpstan analyse -l max --memory-limit=1G src/",
"./vendor/bin/phpcs -p --standard=PSR2 --extensions=php src/"
"./vendor/bin/phpstan analyse -c phpstan.neon -l max --memory-limit=1G src/ tests/",
"./vendor/bin/phpcs -p --standard=PSR2 --extensions=php src/ tests/"
],
"phpcbf": [
"./vendor/bin/phpcbf -p --standard=PSR2 --extensions=php src/"
"./vendor/bin/phpcbf -p --standard=PSR2 --extensions=php src/ tests/"
],
"phpunit": [
"./vendor/bin/phpunit"
]
},
"require": {
"php": "7.3.* || 7.4.* || 8.0.*"
"php": "7.4.* || 8.0.* || 8.1.*"
},
"require-dev": {
"phpstan/phpstan": "0.12.85",
"phpunit/phpunit": "^9.5.4",
"squizlabs/php_codesniffer": "^3.6.0"
"phpstan/phpstan": "1.2.0",
"phpunit/phpunit": "9.5.10",
"squizlabs/php_codesniffer": "3.6.2"
}
}
13 changes: 6 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
parameters:
reportUnmatchedIgnoredErrors: false
ignoreErrors:
-
message: "#^Strict comparison using \\=\\=\\= between string and false will always evaluate to false\\.$#"
count: 1
path: src/AngryBytes/Hash/Hasher/Password.php

# @todo: Remove once we drop PHP 7.4
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- message: "#^Strict comparison using \\=\\=\\= between string and false will always evaluate to false\\.$#"
count: 1
path: src/AngryBytes/Hash/Hasher/Password.php
21 changes: 15 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<?xml version="1.0"?>
<phpunit
bootstrap="./tests/bootstrap.php"
colors="true"
>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
>

<testsuite name="Hasher">
<directory>./tests/AngryBytes/Hash/Test</directory>
</testsuite>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>

<testsuite name="Hasher">
<directory>./tests/AngryBytes/Hash/Test</directory>
</testsuite>

</phpunit>
54 changes: 11 additions & 43 deletions src/AngryBytes/Hash/HMAC.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,28 @@
<?php
/**
* HMAC.php
*
* @category AngryBytes
* @package Hash
* @copyright Copyright (c) 2007-2016 Angry Bytes BV (http://www.angrybytes.com)
*/

namespace AngryBytes\Hash;

use \InvalidArgumentException;

/**
* HMAC creator
*
* This class will generate hashes to be used as HMAC
*
* @category AngryBytes
* @package Hash
*/
class HMAC
{
/**
* Algorithm to use
*
* @var string
**/
private $algorithm;
*/
private string $algorithm;

/**
* Constructor
*
* @param string $algorithm
**/
public function __construct($algorithm)
public function __construct(string $algorithm)
{
$this->setAlgorithm($algorithm);
}

/**
* Does this platform support an algorithm?
*
* @param string $algorithm
* @return bool
**/
public static function platformSupportsAlgorithm($algorithm)
*/
public static function platformSupportsAlgorithm(string $algorithm): bool
{
return in_array($algorithm, hash_algos());
}
Expand All @@ -55,11 +33,9 @@ public static function platformSupportsAlgorithm($algorithm)
* This method accepts multiple variables as input, but is restricted to
* strings. All input will be concatenated before hashing.
*
* @param string $sharedSecret
* @param string[] $args
* @return string
* @param string[] $args
*/
public function hmac($sharedSecret, ...$args)
public function hmac(string $sharedSecret, ...$args): string
{
// Get the data concatenated
$data = '';
Expand All @@ -76,13 +52,8 @@ public function hmac($sharedSecret, ...$args)

/**
* Check if a (received) message has a valid HMAC
*
* @param string $message
* @param string $hmac
* @param string $sharedSecret
* @return bool
**/
public function validHmac($message, $hmac, $sharedSecret)
*/
public function validHmac(string $message, string $hmac, string $sharedSecret): bool
{
// Compare HMAC with received message
return Hash::compare(
Expand All @@ -94,15 +65,12 @@ public function validHmac($message, $hmac, $sharedSecret)

/**
* Set the algorithm to use
*
* @param string $algorithm
* @return HMAC
*/
protected function setAlgorithm($algorithm)
protected function setAlgorithm(string $algorithm): HMAC
{
// Sanity check
if (!self::platformSupportsAlgorithm($algorithm)) {
throw new InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(sprintf(
'"%s" is not a supported hash algorithm on this platform',
$algorithm
));
Expand Down
Loading

0 comments on commit 942ff89

Please sign in to comment.