Skip to content

Commit 18bf65a

Browse files
committed
Experimental packages
0 parents  commit 18bf65a

File tree

9 files changed

+243
-0
lines changed

9 files changed

+243
-0
lines changed

.github/CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Contributing
2+
3+
This repository is a sub repository of [the JWT Framework](https://github.com/web-token/jwt-framework) project and is READ ONLY.
4+
Please do not submit any Pull Requests here. It will be automatically closed.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Please do not submit any Pull Requests here. It will be automatically closed.
2+
3+
You should submit it here: https://github.com/web-token/jwt-framework/pulls

HS1.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2018 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
namespace Jose\Component\Signature\Algorithm;
15+
16+
final class HS1 extends HMAC
17+
{
18+
/**
19+
* @return string
20+
*/
21+
protected function getHashAlgorithm(): string
22+
{
23+
return 'sha1';
24+
}
25+
26+
/**
27+
* @return string
28+
*/
29+
public function name(): string
30+
{
31+
return 'HS1';
32+
}
33+
}

HS256_64.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2018 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
namespace Jose\Component\Signature\Algorithm;
15+
16+
use Jose\Component\Core\JWK;
17+
18+
final class HS256_64 extends HMAC
19+
{
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
protected function getHashAlgorithm(): string
24+
{
25+
return 'sha256';
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function sign(JWK $key, string $input): string
32+
{
33+
$signature = parent::sign($key, $input);
34+
35+
return mb_substr($signature, 0, 8, '8bit');
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function name(): string
42+
{
43+
return 'HS256/64';
44+
}
45+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014-2018 Spomky-Labs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Experimental Signature Algorithms For JWT-Framework
2+
===================================================
3+
4+
This repository is a sub repository of [the JWT Framework](https://github.com/web-token/jwt-framework) project and is READ ONLY.
5+
6+
**Please do not submit any Pull Request here.**
7+
You should go to [the main repository](https://github.com/web-token/jwt-framework) instead.
8+
9+
# Documentation
10+
11+
The official documentation is available as https://web-token.spomky-labs.com/
12+
13+
# Licence
14+
15+
This software is release under [MIT licence](LICENSE).

Tests/HMACSignatureTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2018 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
namespace Jose\Component\Signature\Algorithm\Signature;
15+
16+
use Jose\Component\Core\JWK;
17+
use Jose\Component\Signature\Algorithm\HS1;
18+
use Jose\Component\Signature\Algorithm\HS256_64;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* @group Unit
23+
* @group NewAlgorithm
24+
*/
25+
class HMACSignatureTest extends TestCase
26+
{
27+
public function testHS1SignAndVerify()
28+
{
29+
$key = $this->getKey();
30+
$hmac = new HS1();
31+
$data = 'Live long and Prosper.';
32+
33+
$signature = $hmac->sign($key, $data);
34+
35+
self::assertTrue($hmac->verify($key, $data, $signature));
36+
}
37+
38+
public function testHS256SignAndVerify()
39+
{
40+
$key = $this->getKey();
41+
$hmac = new HS256_64();
42+
$data = 'Live long and Prosper.';
43+
44+
$signature = $hmac->sign($key, $data);
45+
46+
self::assertEquals(hex2bin('89f750759cb8ad93'), $signature);
47+
self::assertTrue($hmac->verify($key, $data, $signature));
48+
}
49+
50+
private function getKey(): JWK
51+
{
52+
return JWK::create([
53+
'kty' => 'oct',
54+
'k' => 'foo',
55+
]);
56+
}
57+
}

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "web-token/jwt-signature-algorithm-experimental",
3+
"description": "Experimental Signature Algorithms the JWT Framework.",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": ["JWS", "JWT", "JWE", "JWA", "JWK", "JWKSet", "Jot", "Jose", "RFC7515", "RFC7516", "RFC7517", "RFC7518", "RFC7519", "RFC7520", "Bundle", "Symfony"],
7+
"homepage": "https://github.com/web-token",
8+
"authors": [
9+
{
10+
"name": "Florent Morselli",
11+
"homepage": "https://github.com/Spomky"
12+
},{
13+
"name": "All contributors",
14+
"homepage": "https://github.com/web-token/jwt-core/contributors"
15+
}
16+
],
17+
"autoload": {
18+
"psr-4": {
19+
"Jose\\Component\\Signature\\Algorithm\\": ""
20+
}
21+
},
22+
"require": {
23+
"web-token/jwt-signature-algorithm-hmac": "^1.2"
24+
},
25+
"require-dev": {
26+
"phpunit/phpunit": "^6.0|^7.0"
27+
},
28+
"extra": {
29+
"branch-alias": {
30+
"dev-master": "1.2.x-dev"
31+
}
32+
},
33+
"config": {
34+
"sort-packages": true
35+
}
36+
}

phpunit.xml.dist

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="true"
11+
bootstrap="vendor/autoload.php"
12+
colors="true">
13+
<testsuites>
14+
<testsuite name="Test Suite">
15+
<directory>./Tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<filter>
20+
<whitelist>
21+
<directory suffix=".php">./</directory>
22+
<exclude>
23+
<directory>./vendor</directory>
24+
<directory>./Tests</directory>
25+
<directory suffix="Test.php">./src</directory>
26+
</exclude>
27+
</whitelist>
28+
</filter>
29+
</phpunit>

0 commit comments

Comments
 (0)