This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6e30b90
Showing
26 changed files
with
894 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/vendor/ | ||
composer.lock | ||
.php_cs.cache | ||
.idea/ | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
if (PHP_SAPI !== 'cli') { | ||
die('This script supports command line usage only. Please check your command.'); | ||
} | ||
|
||
$finder = \PhpCsFixer\Finder::create() | ||
->exclude([ | ||
'vendor', 'build' | ||
]) | ||
->in(__DIR__); | ||
|
||
return \PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@PSR2' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'escape_implicit_backslashes' => [ | ||
'single_quoted' => true | ||
] | ||
]) | ||
->setFinder($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
language: php | ||
dist: trusty | ||
php: | ||
- 7.2 | ||
- 7.3 | ||
- 7.4 | ||
stages: | ||
- lint | ||
- test | ||
- report | ||
before_install: | ||
- openssl aes-256-cbc -K $encrypted_589568f37856_key -iv $encrypted_589568f37856_iv -in secrets.tar.enc -out secrets.tar -d | ||
- tar xvf secrets.tar -C tests/fixtures | ||
- pecl install grpc | ||
install: | ||
- composer update --no-progress --no-interaction --no-suggest | ||
|
||
script: | ||
- vendor/bin/phpunit --testsuite=unit | ||
|
||
jobs: | ||
include: | ||
- stage: lint | ||
name: Code style check | ||
php: '7.2' | ||
script: | ||
- vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation | ||
- stage: test | ||
name: Unit test | ||
script: | ||
- vendor/bin/phpunit --testsuite=integration | ||
- stage: report | ||
name: Code coverage | ||
php: '7.2' | ||
git: | ||
depth: false | ||
script: | ||
- vendor/bin/phpunit --coverage-clover=coverage.xml --log-junit=test-results.xml | ||
- sonar-scanner | ||
branches: | ||
only: | ||
- master | ||
- develop | ||
cache: | ||
directories: | ||
- vendor | ||
- "$HOME/.composer/cache" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "firebase-php/hash", | ||
"description": "Hash algorithm identifiers used by Firebase", | ||
"homepage": "https://github.com/firebase-php/firebase-hash", | ||
"keywords": [ | ||
"firebase", | ||
"php", | ||
"hash algorithms" | ||
], | ||
"type": "library", | ||
"require": { | ||
"php": ">= 7.2" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^8.5", | ||
"friendsofphp/php-cs-fixer": "^2.16" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Trang Nguyen", | ||
"email": "hongtrang2203@gmail.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"FirebaseHash\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"FirebaseHash\\Tests\\": "tests" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="tests/bootstrap.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
<php> | ||
<ini name="date.timezone" value="UTC" /> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
|
||
namespace FirebaseHash; | ||
|
||
class Bcrypt implements Hashable | ||
{ | ||
public function getOptions() | ||
{ | ||
return []; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'BCRYPT'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
|
||
namespace FirebaseHash; | ||
|
||
interface Hashable | ||
{ | ||
public function getOptions(); | ||
|
||
public function getName(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
|
||
namespace FirebaseHash; | ||
|
||
abstract class Hmac implements Hashable | ||
{ | ||
private $key; | ||
|
||
private $name; | ||
|
||
public function __construct(string $name, HmacBuilder $builder) | ||
{ | ||
$this->name = $name; | ||
|
||
if (is_null($builder->getKey()) || strlen($builder->getKey()) === 0) { | ||
throw new \InvalidArgumentException('A non-empty key is required for HMAC algorithm'); | ||
} | ||
$this->key = base64_encode($builder->getKey()); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
abstract public static function builder(); | ||
|
||
public function getOptions() | ||
{ | ||
return [ | ||
'signerKey' => $this->key | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
|
||
namespace FirebaseHash; | ||
|
||
abstract class HmacBuilder | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
private $key; | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getKey(): ?string | ||
{ | ||
return $this->key; | ||
} | ||
|
||
/** | ||
* @param string|null $key | ||
* @return HmacBuilder | ||
*/ | ||
public function setKey(string $key): HmacBuilder | ||
{ | ||
$this->key = $key; | ||
return $this; | ||
} | ||
|
||
abstract public function build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
|
||
namespace FirebaseHash; | ||
|
||
class HmacMd5 extends Hmac | ||
{ | ||
public function __construct($builder) | ||
{ | ||
parent::__construct('HMAC_MD5', $builder); | ||
} | ||
|
||
public static function builder() | ||
{ | ||
return new class extends HmacBuilder { | ||
public function build() | ||
{ | ||
return new HmacMd5($this); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
|
||
namespace FirebaseHash; | ||
|
||
class HmacSha1 extends Hmac | ||
{ | ||
public function __construct($builder) | ||
{ | ||
parent::__construct('HMAC_SHA1', $builder); | ||
} | ||
|
||
public static function builder() | ||
{ | ||
return new class extends HmacBuilder { | ||
public function build() | ||
{ | ||
return new HmacSha1($this); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
|
||
namespace FirebaseHash; | ||
|
||
class HmacSha256 extends Hmac | ||
{ | ||
public function __construct($builder) | ||
{ | ||
parent::__construct('HMAC_SHA256', $builder); | ||
} | ||
|
||
public static function builder() | ||
{ | ||
return new class extends HmacBuilder { | ||
public function build() | ||
{ | ||
return new HmacSha256($this); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace FirebaseHash; | ||
|
||
class HmacSha512 extends Hmac | ||
{ | ||
public function __construct($builder) | ||
{ | ||
parent::__construct('HMAC_SHA512', $builder); | ||
} | ||
|
||
public static function builder() | ||
{ | ||
return new class extends HmacBuilder { | ||
public function build() | ||
{ | ||
return new HmacSha512($this); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
|
||
namespace FirebaseHash; | ||
|
||
class Md5 extends RepeatableHash | ||
{ | ||
public function __construct($builder) | ||
{ | ||
parent::__construct('MD5', 0, 8192, $builder); | ||
} | ||
|
||
public static function builder() | ||
{ | ||
return new class extends RepeatableHashBuilder { | ||
public function build() | ||
{ | ||
return new Md5($this); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
|
||
namespace FirebaseHash; | ||
|
||
class Pbkdf2Sha256 extends RepeatableHash | ||
{ | ||
public function __construct($builder) | ||
{ | ||
parent::__construct('PBKDF2_SHA256', 0, 120000, $builder); | ||
} | ||
|
||
public static function builder() | ||
{ | ||
return new class extends RepeatableHashBuilder { | ||
public function build() | ||
{ | ||
return new Pbkdf2Sha256($this); | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.