Skip to content

Commit

Permalink
Version 0.2.0
Browse files Browse the repository at this point in the history
This version removes the dependency on Defuse, and implements its own
cipher using libsodium crypto secretbox. It also implements an easy
way of creating stateful tokens.
  • Loading branch information
mnavarrocarter committed Dec 28, 2020
1 parent 9de866b commit dc26265
Show file tree
Hide file tree
Showing 20 changed files with 658 additions and 1,004 deletions.
42 changes: 0 additions & 42 deletions .drone.yml

This file was deleted.

11 changes: 9 additions & 2 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<?php

$header = <<<EOF
This file is part of the Legatus project organization.
(c) Matías Navarro-Carter <contact@mnavarro.dev>
@project Legatus Crypto
@link https://github.com/legatus-php/crypto
@package legatus/crypto
@author Matias Navarro-Carter mnavarrocarter@gmail.com
@license MIT
@copyright 2021 Matias Navarro-Carter
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'phpdoc_no_empty_return' => true,
'no_superfluous_phpdoc_tags' => false,
'declare_strict_types' => true,
'header_comment' => ['header' => $header],
'yoda_style' => [
'equal' => false,
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ composer require legatus/crypto

```php
<?php
declare(strict_types=1);

$key = Defuse\Crypto\Key::createNewRandomKey();
$cipher = new Legatus\Support\DefuseCipher($key);
use Legatus\Support\LegatusCipher;
use Legatus\Support\SecretKey;

$secret = SecretKey::generate()->getBytes();
$cipher = new LegatusCipher($secret);

$encrypted = $cipher->encrypt('message');

// You can optionally pass a ttl for verification
try {
$message = $cipher->decrypt($encrypted, 3600); // ttl is optional
} catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $e) {
// There is no access to a CPRNG
$message = $cipher->decrypt($encrypted, 3600);
echo $message; // Writes: "message"
} catch (Legatus\Support\ExpiredCipher $e) {
// The message has passed the ttl
// The encrypted message has passed the ttl
} catch (Legatus\Support\InvalidCipher $e) {
// The message is invalid
// The encrypted message is invalid
}
```

Expand Down
23 changes: 9 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,31 @@
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Legatus\\Support\\": ["src/cipher"]
"Legatus\\Support\\": ["src/cipher", "src/key", "src/rand", "src/token"]
}
},
"autoload-dev": {
"psr-4": {
"Legatus\\Support\\": ["tests/cipher"]
"Legatus\\Support\\": ["tests"]
}
},
"require": {
"php": ">=7.4",
"defuse/php-encryption": "^2.2",
"ext-json": "*",
"ext-sodium": "*",
"lcobucci/clock": "^1.3"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"friendsofphp/php-cs-fixer": "^2.16",
"vimeo/psalm": "^3.7",
"infection/infection": "^0.16.4"
"vimeo/psalm": "^3.7"
},
"scripts": {
"lint": "php-cs-fixer fix --ansi",
"ci:style": "php-cs-fixer fix --dry-run -vvv --ansi",
"ci:test": "phpunit --testdox --coverage-text",
"ci:types": "psalm",
"ci:infection": "infection",
"ci": [
"@ci:types",
"@ci:unit",
"@ci:style",
"@ci:infection"
"pr": [
"php-cs-fixer fix --dry-run -vvv",
"psalm --no-cache --stats",
"XDEBUG_MODE=coverage phpunit --testdox --coverage-text"
]
}
}

0 comments on commit dc26265

Please sign in to comment.