-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- dropped old php Consider dropping PHP 5.x supports #7 - type hints Consider adding the type hints #8 - migrated tests to github workflow
- Loading branch information
Showing
7 changed files
with
300 additions
and
325 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,39 @@ | ||
name: PHP Tests | ||
on: [ push, pull_request ] | ||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
php: [ '7.4', '8.0', '8.1' ] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP, with composer and extensions | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: xdebug | ||
|
||
- name: Validate composer.json and composer.lock | ||
run: composer validate | ||
|
||
- name: Cache Composer packages | ||
id: composer-cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: vendor | ||
key: ${{ runner.os }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.php }}- | ||
- name: Install dependencies | ||
if: steps.composer-cache.outputs.cache-hit != 'true' | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: Run tests | ||
run: vendor/bin/phpunit --coverage-text |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,78 +1,79 @@ | ||
# Shorten and obfuscate IDs | ||
|
||
[![Build Status](https://travis-ci.org/krowinski/tinyID.svg?branch=master)](https://travis-ci.org/krowinski/tinyID) | ||
[![Latest Stable Version](https://poser.pugx.org/krowinski/tinyid/v/stable)](https://packagist.org/packages/krowinski/tinyid) [![Total Downloads](https://poser.pugx.org/krowinski/tinyid/downloads)](https://packagist.org/packages/krowinski/tinyid) [![Latest Unstable Version](https://poser.pugx.org/krowinski/tinyid/v/unstable)](https://packagist.org/packages/krowinski/tinyid) | ||
[![License](https://poser.pugx.org/krowinski/tinyid/license)](https://packagist.org/packages/krowinski/tinyid) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/krowinski/tinyid/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/krowinski/tinyid/?branch=master) | ||
[![Code Coverage](https://scrutinizer-ci.com/g/krowinski/tinyid/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/krowinski/tinyid/?branch=master) | ||
|
||
## SYNOPSIS | ||
|
||
```php | ||
use TinyID\TinyID; | ||
|
||
include __DIR__ . '/../vendor/autoload.php'; | ||
|
||
// dictionary must consist of at least two UNIQUE unicode characters. | ||
$tinyId = new TinyID('2BjLhRduC6Tb8Q5cEk9oxnFaWUDpOlGAgwYzNre7tI4yqPvXm0KSV1fJs3ZiHM'); | ||
|
||
var_dump($tinyId->encode('48888851145')); // will print 1FN7Ab | ||
var_dump($tinyId->decode('1FN7Ab')); // will print 48888851145 | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
Using real IDs in various places - such as GET links or API payload - is generally a bad idea: | ||
|
||
* It may reveal some sensitive informations about your business, such as growth rate or amount of customers. | ||
* If someone finds unprotected resource link, where you forgot to check if passed resource ID really belongs to currently logged-in user, he will be able to steal all of your data really fast just by incrementing ID in links. | ||
* Big numbers may cause overflows in places where length is limited, such as SMS messages. | ||
|
||
With the help of this module you can shorten and obfuscate your IDs at the same time. | ||
|
||
## METHODS | ||
|
||
### new TidyID('qwerty') | ||
|
||
Key must consist of at least two ***unique*** unicode characters. | ||
|
||
The longer the dictionary - the shorter encoded ID. | ||
|
||
Encoded ID will be made exclusively out of characters from the key. | ||
This very useful property allows to adapt your encoding to the environment. | ||
For example in SMS messages you may restrict key to US ASCII to avoid available length reduction caused by conversion to GSM 03.38 charset. | ||
Or if you want to use such ID as file/directory name in case insensitive filesystem you may want to use only lowercase letters in the key. | ||
|
||
### encode(123) | ||
|
||
Encode positive integer into a string. | ||
|
||
Note that leading `0`s are not preserved, `encode(123)` is the same as `encode(00123)`. | ||
|
||
Used algorithm is a base to the length of the key conversion that maps to distinct permutation of characters. | ||
Do not consider it a strong encryption, but if you have secret and long and well shuffled key it is almost impossible to reverse-engineer real ID. | ||
|
||
### decode('rer') | ||
|
||
Decode string back into a positive integer. | ||
|
||
## TRICKS | ||
|
||
If you provide sequential characters in key you can convert your numbers to some weird numeric systems, for example base18: | ||
|
||
```php | ||
var_dump((new TinyID('0123456789ABCDEFGH'))->encode(48888851145)); // '47F709HFF' | ||
``` | ||
|
||
Or you can go wild just for the fun of it. | ||
|
||
```php | ||
var_dump((new TinyID('๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ'))->encode(48888851145)); // '๐ญ๐ข๐๐๐ซ๐' | ||
``` | ||
|
||
## OTHER IMPLEMENTATIONS | ||
|
||
* [Perl 5](http://search.cpan.org/~bbkr/Integer-Tiny-0.3/lib/Integer/Tiny.pm) | ||
* [Perl 6](https://github.com/bbkr/TinyID) | ||
|
||
All examples are in example dir. | ||
# Shorten and obfuscate IDs | ||
|
||
[![PHP Tests](https://github.com/krowinski/tinyID/actions/workflows/tests.yml/badge.svg)](https://github.com/krowinski/tinyID/actions/workflows/tests.yml) | ||
[![Latest Stable Version](https://poser.pugx.org/krowinski/tinyid/v/stable)](https://packagist.org/packages/krowinski/tinyid) | ||
[![Total Downloads](https://poser.pugx.org/krowinski/tinyid/downloads)](https://packagist.org/packages/krowinski/tinyid) | ||
[![License](https://poser.pugx.org/krowinski/tinyid/license)](https://packagist.org/packages/krowinski/tinyid) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/krowinski/tinyid/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/krowinski/tinyid/?branch=master) | ||
[![Code Coverage](https://scrutinizer-ci.com/g/krowinski/tinyid/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/krowinski/tinyid/?branch=master) | ||
|
||
## SYNOPSIS | ||
|
||
```php | ||
use TinyID\TinyID; | ||
|
||
include __DIR__ . '/../vendor/autoload.php'; | ||
|
||
// dictionary must consist of at least two UNIQUE unicode characters. | ||
$tinyId = new TinyID('2BjLhRduC6Tb8Q5cEk9oxnFaWUDpOlGAgwYzNre7tI4yqPvXm0KSV1fJs3ZiHM'); | ||
|
||
var_dump($tinyId->encode('48888851145')); // will print 1FN7Ab | ||
var_dump($tinyId->decode('1FN7Ab')); // will print '48888851145' | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
Using real IDs in various places - such as GET links or API payload - is generally a bad idea: | ||
|
||
* It may reveal some sensitive information about your business, such as growth rate or amount of customers. | ||
* If someone finds unprotected resource link, where you forgot to check if passed resource ID really belongs to currently logged-in user, he will be able to steal all of your data really fast just by | ||
incrementing ID in links. | ||
* Big numbers may cause overflows in places where length is limited, such as SMS messages. | ||
|
||
With the help of this module you can shorten and obfuscate your IDs at the same time. | ||
|
||
## METHODS | ||
|
||
### new TidyID('qwerty') | ||
|
||
Key must consist of at least two ***unique*** unicode characters. | ||
|
||
The longer the dictionary - the shorter encoded ID. | ||
|
||
Encoded ID will be made exclusively out of characters from the key. This very useful property allows to adapt your encoding to the environment. For example in SMS messages you may restrict key to US | ||
ASCII to avoid available length reduction caused by conversion to GSM 03.38 charset. Or if you want to use such ID as file/directory name in case-insensitive filesystem you may want to use only | ||
lowercase letters in the key. | ||
|
||
### encode('123') | ||
|
||
Encode positive integer into a string. | ||
|
||
Note that leading `0`s are not preserved, `encode('123')` is the same as `encode('00123')`. | ||
|
||
Used algorithm is a base to the length of the key conversion that maps to distinct permutation of characters. Do not consider it a strong encryption, but if you have secret and long and well shuffled | ||
key it is almost impossible to reverse-engineer real ID. | ||
|
||
### decode('rer') | ||
|
||
Decode string back into a positive integer. | ||
|
||
## TRICKS | ||
|
||
If you provide sequential characters in key you can convert your numbers to some weird numeric systems, for example base18: | ||
|
||
```php | ||
var_dump((new TinyID('0123456789ABCDEFGH'))->encode('48888851145')); // '47F709HFF' | ||
``` | ||
|
||
Or you can go wild just for the fun of it. | ||
|
||
```php | ||
var_dump((new TinyID('๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ'))->encode(48888851145)); // '๐ญ๐ข๐๐๐ซ๐' | ||
``` | ||
|
||
## OTHER IMPLEMENTATIONS | ||
|
||
* [Perl 5](http://search.cpan.org/~bbkr/Integer-Tiny-0.3/lib/Integer/Tiny.pm) | ||
* [Perl 6](https://github.com/bbkr/TinyID) | ||
|
||
Examples are in example dir. |
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
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 |
---|---|---|
@@ -1,15 +1,17 @@ | ||
<?php | ||
|
||
use TinyID\TinyID; | ||
|
||
include __DIR__ . '/../vendor/autoload.php'; | ||
|
||
// dictionary must consist of at least two UNIQUE unicode characters. | ||
$tinyId = new TinyID('2BjLhRduC6Tb8Q5cEk9oxnFaWUDpOlGAgwYzNre7tI4yqPvXm0KSV1fJs3ZiHM'); | ||
|
||
var_dump($tinyId->encode('48888851145')); // 1FN7Ab | ||
var_dump($tinyId->decode('1FN7Ab')); // 48888851145 | ||
|
||
var_dump((new TinyID('0123456789ABCDEFGH'))->encode(48888851145)); // '47F709HFF' | ||
|
||
var_dump((new TinyID('๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ'))->encode(48888851145)); // '๐ญ๐ข๐๐๐ซ๐' | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use TinyID\TinyID; | ||
|
||
include __DIR__ . '/../vendor/autoload.php'; | ||
|
||
// dictionary must consist of at least two UNIQUE unicode characters. | ||
$tinyId = new TinyID('2BjLhRduC6Tb8Q5cEk9oxnFaWUDpOlGAgwYzNre7tI4yqPvXm0KSV1fJs3ZiHM'); | ||
|
||
var_dump($tinyId->encode('48888851145')); // 1FN7Ab | ||
var_dump($tinyId->decode('1FN7Ab')); // 48888851145 | ||
|
||
var_dump((new TinyID('0123456789ABCDEFGH'))->encode('48888851145')); // '47F709HFF' | ||
|
||
var_dump((new TinyID('๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ'))->encode('48888851145')); // '๐ญ๐ข๐๐๐ซ๐' |
Oops, something went wrong.