Skip to content

Commit 9039991

Browse files
committed
Re-add support for 7.1
1 parent 9b79f69 commit 9039991

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ sudo: false
22

33
language: php
44
php:
5+
- 7.1
56
- 7.2
67
- nightly
78
- hhvm
@@ -14,7 +15,7 @@ matrix:
1415

1516
before_install:
1617
- export ALLOW_FAILURE=1; if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then export ALLOW_FAILURE=0; fi
17-
- pecl install mcrypt-1.0.2
18+
- if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then yes '' | pecl install mcrypt-1.0.2; fi
1819

1920
install:
2021
- composer self-update

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ secure version of a credential for storage (rather than storing passwords in "pl
1919
## Requirements
2020

2121
- 64-bit PHP runtime (NTLM negotiation bit flags extend beyond the 32-bit integer size)
22-
- PHP `>=7.2.0`
22+
- PHP `>=7.1.0`
2323

2424

2525
## Installation

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"source": "https://github.com/robinpowered/php-ntlm"
1717
},
1818
"require": {
19-
"php-64bit": ">=7.2.0"
19+
"php-64bit": ">=7.1.0"
2020
},
2121
"require-dev": {
2222
"ext-mcrypt": "*",

src/Robin/Ntlm/Crypt/Hasher/AbstractHasher.php

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Robin\Ntlm\Crypt\Hasher;
1212

1313
use HashContext;
14+
use InvalidArgumentException;
1415

1516
/**
1617
* A cryptographic hasher implemented using PHP's built-in hashing mechanisms as
@@ -20,21 +21,45 @@
2021
*/
2122
abstract class AbstractHasher implements HasherInterface
2223
{
24+
25+
/**
26+
* Constants
27+
*/
28+
29+
/**
30+
* The "resource" type of a PHP hash context.
31+
*
32+
* @type string
33+
*/
34+
35+
const HASH_CONTEXT_RESOURCE_TYPE = 'Hash Context';
36+
37+
38+
/**
39+
* Properties
40+
*/
41+
2342
/**
2443
* The incremental hashing context.
2544
*
26-
* @type HashContext
45+
* @link http://php.net/manual/en/hash.resources.php
46+
* @type resource|HashContext
2747
*/
2848
private $context;
2949

50+
51+
/**
52+
* Methods
53+
*/
54+
3055
/**
3156
* Constructor
3257
*
33-
* @param HashContext $context The incremental hashing context.
58+
* @param resource|HashContext $context The incremental hashing context.
3459
*/
35-
protected function __construct(HashContext $context)
60+
protected function __construct($context)
3661
{
37-
$this->context = $context;
62+
$this->context = $this->validateHashContext($context);
3863
}
3964

4065
/**
@@ -63,4 +88,25 @@ public function digest(): string
6388

6489
return $digest;
6590
}
91+
92+
/**
93+
* Validates a given incremental hashing context.
94+
*
95+
* @link http://php.net/manual/en/hash.resources.php
96+
* @param mixed $context The context to validate.
97+
* @return resource|HashContext The incremental hashing context.
98+
* @throws InvalidArgumentException If the hash context isn't valid.
99+
*/
100+
protected function validateHashContext($context)
101+
{
102+
if (!($context instanceof HashContext) && (false === $context
103+
|| !is_resource($context)
104+
|| (is_resource($context) && static::HASH_CONTEXT_RESOURCE_TYPE !== get_resource_type($context)))) {
105+
throw new InvalidArgumentException(
106+
'Unable to initialize hashing context. Your system might not support the supplied algorithm.'
107+
);
108+
}
109+
110+
return $context;
111+
}
66112
}

0 commit comments

Comments
 (0)