Skip to content

Commit

Permalink
Merge pull request #7 from mitwork/dev
Browse files Browse the repository at this point in the history
Sync main
  • Loading branch information
eudj1n committed Oct 13, 2023
2 parents 31dd8fd + 95beee4 commit a4219f3
Show file tree
Hide file tree
Showing 34 changed files with 413 additions and 53 deletions.
22 changes: 18 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# История версий

## Текущая версия
## V1.0.3

- Переводы и локализация;
- Дополнительные исключения `KalkanExtractionException`, `KalkanSignatureException`, `KalkanValidationException`;
- Базовые события `DocumentSaved`, `DocumentSigned`, `DocumentRejected`.

## V1.0.2

- Исправления тестов и документации;
- Метод проверки статуса документов.

## V1.0.1

- Исправления тестов и документации.

## V1.0.0

- Реализованы базовые возможности.

- Подписание и проверка XML данных;
- Подписание и проверка бинарных данных (CMS);
- Генерация QR-кодов.
12 changes: 12 additions & 0 deletions lang/en/exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

return [
'incorrect_base64_data' => 'Incorrect base64 data.',
'incorrect_json_data' => 'Incorrect JSON data.',
'incorrect_xml_data' => 'Incorrect XML data: :error.',
'incorrect_ncanode_status' => 'Incorrect NCANode response :status - :message.',
'ncanode_is_unavailable' => 'NCANode is unavailable - :error.',
'signature_error' => 'Signature error - :error.',
'validation_error' => 'Signature validation - :error.',
'extraction_error' => 'Extraction error - :error.',
];
8 changes: 8 additions & 0 deletions lang/en/messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'unable_to_save_document' => 'Unable to save document.',
'unable_to_get_document' => 'Unable to get document.',
'unable_to_process_document' => 'Unable to process document.',
'document_not_found' => 'Document not found.',
];
12 changes: 12 additions & 0 deletions lang/kk/exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

return [
'incorrect_base64_data' => 'Base64 деректері дұрыс емес.',
'incorrect_json_data' => 'Дұрыс емес JSON деректері.',
'incorrect_xml_data' => 'Дұрыс емес XML деректері.: :error.',
'incorrect_ncanode_status' => 'Дұрыс емес жауап күйі :status - :message.',
'ncanode_is_unavailable' => 'NCANode қызметі қолжетімсіз - :error.',
'signature_error' => 'Деректерге қол қою қатесі - :error.',
'validation_error' => 'Деректерді тексеру қатесі - :error.',
'extraction_error' => 'Деректерді іздеу қатесі - :error.',
];
8 changes: 8 additions & 0 deletions lang/kk/messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'unable_to_save_document' => 'Құжатты сақтау мүмкін емес..',
'unable_to_get_document' => 'Құжатты алу мүмкін емес.',
'unable_to_process_document' => 'Құжатты өңдеу мүмкін емес.',
'document_not_found' => 'Құжат табылмады.',
];
12 changes: 12 additions & 0 deletions lang/ru/exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

return [
'incorrect_base64_data' => 'Некорректные base64 данные.',
'incorrect_json_data' => 'Некорректные JSON данные.',
'incorrect_xml_data' => 'Некорректные XML данные: :error.',
'incorrect_ncanode_status' => 'Некорректный статус ответа :status - :message.',
'ncanode_is_unavailable' => 'Сервис NCANode недоступен - :error.',
'signature_error' => 'Ошибка подписания данных - :error.',
'validation_error' => 'Ошибка проверки данных - :error.',
'extraction_error' => 'Ошибка извлечения данных - :error.',
];
8 changes: 8 additions & 0 deletions lang/ru/messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'unable_to_save_document' => 'Невозможно сохранить документ.',
'unable_to_get_document' => 'Невозможно получить документ.',
'unable_to_process_document' => 'Невозможно обработать документ.',
'document_not_found' => 'Документ не найден.',
];
12 changes: 10 additions & 2 deletions src/Contracts/SignatureService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Mitwork\Kalkan\Enums\TsaPolicy;
use Mitwork\Kalkan\Exceptions\IncorrectXmlDataException;
use Mitwork\Kalkan\Exceptions\KalkanSignatureException;
use Mitwork\Kalkan\Exceptions\NcanodeStatusException;
use Mitwork\Kalkan\Exceptions\NcanodeUnavailableException;

interface SignatureService
Expand All @@ -18,12 +20,15 @@ interface SignatureService
* @param bool $clearSignatures Очистка подписи
* @param bool $trimXml Очистка XML
* @param bool $raw Возврат подписанной строки, либо ответа
* @param bool $throw Возврат исключения в случае ошибки
* @return string|array Подписанные данные или ответ сервиса
*
* @throws IncorrectXmlDataException
* @throws NcanodeUnavailableException
* @throws NcanodeStatusException
* @throws KalkanSignatureException
*/
public function signXml(string $xml, string $key, string $password, string $alias = null, bool $clearSignatures = false, bool $trimXml = false, bool $raw = false): string|array;
public function signXml(string $xml, string $key, string $password, string $alias = null, bool $clearSignatures = false, bool $trimXml = false, bool $raw = false, bool $throw = false): string|array;

/**
* Подписание CMS-данных
Expand All @@ -37,9 +42,12 @@ public function signXml(string $xml, string $key, string $password, string $alia
* @param bool $detached Открепленная подпись
* @param string|null $cms Исходные (подписанные данные)
* @param bool $raw Возврат подписанной строки, либо ответа
* @param bool $throw Возврат исключения в случае ошибки
* @return string|array Подписанные данные или ответ сервиса
*
* @throws NcanodeUnavailableException
* @throws NcanodeStatusException
* @throws KalkanSignatureException
*/
public function signCms(string $data, string $key, string $password, string $alias = null, bool $withTsp = true, TsaPolicy $tsaPolicy = TsaPolicy::TSA_GOST_POLICY, bool $detached = false, string $cms = null, bool $raw = false): string|array;
public function signCms(string $data, string $key, string $password, string $alias = null, bool $withTsp = true, TsaPolicy $tsaPolicy = TsaPolicy::TSA_GOST_POLICY, bool $detached = false, string $cms = null, bool $raw = false, bool $throw = false): string|array;
}
18 changes: 16 additions & 2 deletions src/Contracts/ValidationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Mitwork\Kalkan\Contracts;

use Mitwork\Kalkan\Exceptions\KalkanValidationException;
use Mitwork\Kalkan\Exceptions\NcanodeStatusException;
use Mitwork\Kalkan\Exceptions\NcanodeUnavailableException;

interface ValidationService
{
/**
Expand All @@ -11,9 +15,14 @@ interface ValidationService
* @param bool $verifyCrl Проверка по CRL
* @param bool $verifyOcsp Проверка OCSP
* @param bool $raw Возврат результата, либо ответа
* @param bool $throw Возврат исключения в случае ошибки
* @return bool|array Результат, либо ответ
*
* @throws NcanodeUnavailableException
* @throws NcanodeStatusException
* @throws KalkanValidationException
*/
public function verifyXml(string $xml, bool $verifyCrl = true, bool $verifyOcsp = true, bool $raw = false): bool|array;
public function verifyXml(string $xml, bool $verifyCrl = true, bool $verifyOcsp = true, bool $raw = false, bool $throw = false): bool|array;

/**
* Проверка подписанных CMS-данных
Expand All @@ -23,7 +32,12 @@ public function verifyXml(string $xml, bool $verifyCrl = true, bool $verifyOcsp
* @param bool $verifyCrl Проверка по CRL
* @param bool $verifyOcsp Проверка OCSP
* @param bool $raw Возврат результата, либо ответа
* @param bool $throw Возврат исключения в случае ошибки
* @return bool|array Результат, либо ответ
*
* @throws NcanodeUnavailableException
* @throws NcanodeStatusException
* @throws KalkanValidationException
*/
public function verifyCms(string $cms, string $data, bool $verifyCrl = true, bool $verifyOcsp = true, bool $raw = false): bool|array;
public function verifyCms(string $cms, string $data, bool $verifyCrl = true, bool $verifyOcsp = true, bool $raw = false, bool $throw = false): bool|array;
}
21 changes: 21 additions & 0 deletions src/Events/DocumentRejected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Mitwork\Kalkan\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;

class DocumentRejected
{
use Dispatchable, InteractsWithSockets;

public int|string $id;

public string $message;

public function __construct($id, $message)
{
$this->id = $id;
$this->message = $message;
}
}
17 changes: 17 additions & 0 deletions src/Events/DocumentSaved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Mitwork\Kalkan\Events;

use Illuminate\Foundation\Events\Dispatchable;

class DocumentSaved
{
use Dispatchable;

public int|string $id;

public function __construct($id)
{
$this->id = $id;
}
}
24 changes: 24 additions & 0 deletions src/Events/DocumentSigned.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Mitwork\Kalkan\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;

class DocumentSigned
{
use Dispatchable, InteractsWithSockets;

public int|string $id;

public string $content;

public string $signature;

public function __construct($id, $content, $signature)
{
$this->id = $id;
$this->content = $content;
$this->signature = $signature;
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/IncorrectBase64DataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class IncorrectBase64DataException extends InvalidArgumentException
{
public static function create(): self
{
return new static('Некорректные Base64 данные');
return new static(__('kalkan::exceptions.incorrect_base64_data'));
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/IncorrectJsonDataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class IncorrectJsonDataException extends InvalidArgumentException
{
public static function create(): self
{
return new static('Некорректные JSON-данные');
return new static(__('kalkan::exceptions.incorrect_json_data'));
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/IncorrectXmlDataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class IncorrectXmlDataException extends InvalidArgumentException
{
public static function create(string $error): self
{
return new static("Некорректные XML-данные: `{$error}`");
return new static(__('kalkan::exceptions.incorrect_xml_data', ['error' => $error]));
}
}
17 changes: 17 additions & 0 deletions src/Exceptions/KalkanExtractionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Mitwork\Kalkan\Exceptions;

use InvalidArgumentException;

class KalkanExtractionException extends InvalidArgumentException
{
public static function create(string|array $error): self
{
if (is_array($error)) {
$error = print_r($error, true);
}

return new static(__('kalkan::exceptions.extraction_error', ['error' => $error]));
}
}
17 changes: 17 additions & 0 deletions src/Exceptions/KalkanSignatureException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Mitwork\Kalkan\Exceptions;

use InvalidArgumentException;

class KalkanSignatureException extends InvalidArgumentException
{
public static function create(string|array $error): self
{
if (is_array($error)) {
$error = print_r($error, true);
}

return new static(__('kalkan::exceptions.signature_error', ['error' => $error]));
}
}
17 changes: 17 additions & 0 deletions src/Exceptions/KalkanValidationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Mitwork\Kalkan\Exceptions;

use InvalidArgumentException;

class KalkanValidationException extends InvalidArgumentException
{
public static function create(string|array $error): self
{
if (is_array($error)) {
$error = print_r($error, true);
}

return new static(__('kalkan::exceptions.validation_error', ['error' => $error]));
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/NcanodeStatusException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class NcanodeStatusException extends InvalidArgumentException
{
public static function create(int $status, string $message = ''): self
{
return new static("Некорректный статус ответ: `{$status}` с сообщением: `{$message}`");
return new static(__('kalkan::exceptions.incorrect_ncanode_status', ['status' => $status, 'message' => $message]));
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/NcanodeUnavailableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class NcanodeUnavailableException extends InvalidArgumentException
{
public static function create(string $error): self
{
return new static("Сервис NCANode недоступен: `{$error}`.");
return new static(__('kalkan::exceptions.ncanode_is_unavailable', ['error' => $error]));
}
}
Loading

0 comments on commit a4219f3

Please sign in to comment.