Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Класс TimeSigner

Открытые члены

 __construct (SigningAlgorithm $algorithm=null)
 
 setKey ($value)
 
 getSeparator ()
 
 setSeparator ($value)
 
 sign ($value, $time, $salt=null)
 
 unsign ($signedValue, $salt=null)
 
 getSignature ($value, $timestamp, $salt=null)
 
 validate ($value, $timestamp, $signature, $salt=null)
 
 pack (array $values)
 
 unpack ($value, $limit=2)
 

Защищенные члены

 getTimeStamp ($time)
 

Защищенные данные

 $signer = null
 

Подробное описание

См. определение в файле timesigner.php строка 12

Конструктор(ы)

◆ __construct()

__construct ( SigningAlgorithm $algorithm = null)

Creates new TimeSigner object. If you want use your own signing algorithm - you can this

Аргументы
SigningAlgorithm$algorithmCustom signing algorithm.

См. определение в файле timesigner.php строка 22

Методы

◆ getSeparator()

getSeparator ( )

Return separator, used for packing/unpacking

Возвращает
string

См. определение в файле timesigner.php строка 45

◆ getSignature()

getSignature ( $value,
$timestamp,
$salt = null )

Return message signature

Аргументы
string$valueMessage.
int$timestampExpire timestamp.
null$saltSalt (if needed).
Возвращает
string
Исключения
ArgumentTypeException

См. определение в файле timesigner.php строка 155

◆ getTimeStamp()

getTimeStamp ( $time)
protected

Return timestamp parsed from English textual datetime description

Аргументы
string | int$timeTimestamp or datetime description (presented in format accepted by strtotime).
Возвращает
int
Исключения

Bitrix\Main\ArgumentTypeException

Исключения

Bitrix\Main\ArgumentException

См. определение в файле timesigner.php строка 195

◆ pack()

pack ( array $values)

Pack array values to single string: pack(['test', 'all', 'values']) -> 'test.all.values'

Аргументы
array$valuesValues for packing.
Возвращает
string

См. определение в файле timesigner.php строка 224

◆ setKey()

setKey ( $value)

Set key for signing

Аргументы
string$valueKey.
Возвращает
$this
Исключения

Bitrix\Main\ArgumentTypeException

См. определение в файле timesigner.php строка 34

◆ setSeparator()

setSeparator ( $value)

Set separator, used for packing/unpacking

Аргументы
string$valueSeparator.
Возвращает
$this
Исключения

Bitrix\Main\ArgumentTypeException

См. определение в файле timesigner.php строка 57

◆ sign()

sign ( $value,
$time,
$salt = null )

Sign message with expired time, return string in format: {message}{separator}{expired timestamp}{separator}{signature}

Simple example: // If salt needed $foo = (new TimeSigner)->sign('test', '+1 hour', 'my_salt');

// Otherwise $bar = (new TimeSigner)->sign('test', '+1 day');

Аргументы
string$valueMessage for signing.
string$timeTimestamp or datetime description (presented in format accepted by strtotime).
string | null$saltSalt, if needed.
Возвращает
string

См. определение в файле timesigner.php строка 81

◆ unpack()

unpack ( $value,
$limit = 2 )

Unpack values from string (something like rsplit). Simple example for separator ".": // Unpack all values: unpack('test.all.values', 0) -> ['test', 'all', 'values']

// Unpack 2 values (by default). First element containing the rest of string. unpack('test.all.values') -> ['test.all', 'values']

// Exception if separator is missing unpack('test.all values', 3) -> throws BadSignatureException

Аргументы
string$valueString for unpacking.
int$limitIf $limit === 0 - unpack all values, default - 2.
Возвращает
array
Исключения
BadSignatureException

См. определение в файле timesigner.php строка 248

◆ unsign()

unsign ( $signedValue,
$salt = null )

Check message signature and it lifetime. If everything is OK - return original message.

Simple example: $signer = new TimeSigner;

// Sing message for 1 second $signedValue = $signer->sign('test', '+1 second');

// Or sign with expiring on some magic timestamp (e.g. 01.01.2030) $signedValue = $signer->sign('test', 1893445200);

// Get original message with checking echo $signer->unsign($signedValue); // Output: 'test'

// Try to unsigning not signed value echo $signer->unsign('test'); //throw BadSignatureException with message 'Separator not found in value'

// Or with invalid sign echo $signer->unsign('test.invalid_sign');

// Or invalid salt echo $signer->unsign($signedValue, 'invalid_salt'); //throw BadSignatureException with message 'Signature does not match'

// Or expired lifetime echo $signer->unsign($signedValue); //throw BadSignatureException with message 'Signature timestamp expired (1403039921 < 1403040024)'

Аргументы
string$signedValueSigned value, must be in format: {message}{separator}{expired timestamp}{separator}{signature}.
string | null$saltSalt, if used while signing.
Возвращает
string
Исключения
BadSignatureException

См. определение в файле timesigner.php строка 127

◆ validate()

validate ( $value,
$timestamp,
$signature,
$salt = null )

Simply validation of message signature

Аргументы
string$valueMessage.
int$timestampExpire timestamp.
string$signatureSignature.
string | null$saltSalt, if used while signing.
Возвращает
bool True if OK, otherwise - false.

См. определение в файле timesigner.php строка 173

Данные класса

◆ $signer

$signer = null
protected

См. определение в файле timesigner.php строка 15