Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php_cs #13

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

require_once './vendor/autoload.php';

use Nextcloud\CodingStandard\Config;

$config = new Config();
$config
->getFinder()
->ignoreVCSIgnored(true)
->notPath('build')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->in(__DIR__);
return $config;
20 changes: 10 additions & 10 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

return [
'routes' => [
['name' => 'api#preflighted_cors', 'url' => '/api/0.1/{path}',
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+'], ],
['name' => 'libresign#sign', 'url' => '/api/0.1/sign', 'verb' => 'POST'],
['name' => 'signature#generate', 'url' => '/api/0.1/signature/generate', 'verb' => 'POST'],
['name' => 'signature#hasRootCert', 'url' => '/api/0.1/signature/has-root-cert', 'verb' => 'GET'],
['name' => 'admin#generateCertificate', 'url' => '/api/0.1/admin/certificate', 'verb' => 'POST'],
['name' => 'admin#loadCertificate', 'url' => '/api/0.1/admin/certificate', 'verb' => 'GET'],
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
],
'routes' => [
['name' => 'api#preflighted_cors', 'url' => '/api/0.1/{path}',
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+'], ],
['name' => 'libresign#sign', 'url' => '/api/0.1/sign', 'verb' => 'POST'],
['name' => 'signature#generate', 'url' => '/api/0.1/signature/generate', 'verb' => 'POST'],
['name' => 'signature#hasRootCert', 'url' => '/api/0.1/signature/has-root-cert', 'verb' => 'GET'],
['name' => 'admin#generateCertificate', 'url' => '/api/0.1/admin/certificate', 'verb' => 'POST'],
['name' => 'admin#loadCertificate', 'url' => '/api/0.1/admin/certificate', 'verb' => 'GET'],
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
],
];
2 changes: 1 addition & 1 deletion dsv/appinfo/app.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

if (false === (@include_once __DIR__.'/../lib/vendor/autoload.php')) {
throw new Exception('Cannot include autoload. Did you run install dependencies using composer?');
throw new Exception('Cannot include autoload. Did you run install dependencies using composer?');
}
$app = \OC::$server->query(OCA\Dsv\AppInfo\Application::class);
2 changes: 1 addition & 1 deletion dsv/appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return ['routes' => [
['name' => 'dsv#get', 'url' => '/get', 'verb' => 'GET'],
['name' => 'dsv#get', 'url' => '/get', 'verb' => 'GET'],
]];
38 changes: 18 additions & 20 deletions dsv/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@

use OCP\AppFramework\App;

class Application extends App
{
const APP_NAME = 'dsv';
class Application extends App {
public const APP_NAME = 'dsv';

/**
* Application constructor.
*
* @throws \OCP\AppFramework\QueryException
*/
public function __construct(array $params = [])
{
parent::__construct(self::APP_NAME, $params);
/**
* Application constructor.
*
* @throws \OCP\AppFramework\QueryException
*/
public function __construct(array $params = []) {
parent::__construct(self::APP_NAME, $params);

$container = $this->getContainer();
$server = $container->getServer();
$eventDispatcher = $server->getEventDispatcher();
$container = $this->getContainer();
$server = $container->getServer();
$eventDispatcher = $server->getEventDispatcher();

$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function () {
\OCP\Util::addStyle(self::APP_NAME, 'tabview');
\OCP\Util::addScript(self::APP_NAME, 'tabview');
\OCP\Util::addScript(self::APP_NAME, 'plugin');
});
}
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function () {
\OCP\Util::addStyle(self::APP_NAME, 'tabview');
\OCP\Util::addScript(self::APP_NAME, 'tabview');
\OCP\Util::addScript(self::APP_NAME, 'plugin');
});
}
}
59 changes: 28 additions & 31 deletions dsv/lib/Controller/DsvController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,36 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;

class DsvController extends Controller
{
protected $metadataService;
class DsvController extends Controller {
protected $metadataService;

public function __construct($appName, IRequest $request, DsvService $metadataService)
{
parent::__construct($appName, $request);
$this->metadataService = $metadataService;
}
public function __construct($appName, IRequest $request, DsvService $metadataService) {
parent::__construct($appName, $request);
$this->metadataService = $metadataService;
}

/**
* @NoAdminRequired
*
* @param mixed $source
*/
public function get($source)
{
try {
$signatures = $this->metadataService->getSignatures($source);
/**
* @NoAdminRequired
*
* @param mixed $source
*/
public function get($source) {
try {
$signatures = $this->metadataService->getSignatures($source);

return new JSONResponse([
'response' => 'success',
'signatures' => $signatures,
]);
} catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, ['app' => Application::APP_NAME]);
return new JSONResponse([
'response' => 'success',
'signatures' => $signatures,
]);
} catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, ['app' => Application::APP_NAME]);

return new JSONResponse(
[
'response' => 'error',
'msg' => 'Erro ao consultar assinatura digital, verifique os logs do sistema para mais detalhes.',
]
);
}
}
return new JSONResponse(
[
'response' => 'error',
'msg' => 'Erro ao consultar assinatura digital, verifique os logs do sistema para mais detalhes.',
]
);
}
}
}
155 changes: 75 additions & 80 deletions dsv/lib/Service/DsvService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,90 @@

use OC\Files\Filesystem;

class DsvService
{
/**
* @NoAdminRequired
*
* @param mixed $source
*
* @throws \Exception
*/
public function getSignatures($source)
{
$file = Filesystem::getLocalFile($source);
if (!$file) {
throw new \Exception('Arquivo não encontrado.');
}
class DsvService {
/**
* @NoAdminRequired
*
* @param mixed $source
*
* @throws \Exception
*/
public function getSignatures($source) {
$file = Filesystem::getLocalFile($source);
if (!$file) {
throw new \Exception('Arquivo não encontrado.');
}

$signaturesInfo = $this->signaturesInfo($file);
$signaturesInfo = $this->signaturesInfo($file);

$data = [];
foreach ($signaturesInfo as $sigKey => $signature) {
$signatureInfo = [];
foreach ($signature as $key => $value) {
list($label, $value) = $this->translate($key, $value);
if (!$label) {
continue;
}
$signatureInfo[$key] = ['label' => $label, 'value' => $value];
}
$data[$sigKey] = $signatureInfo;
}
$data = [];
foreach ($signaturesInfo as $sigKey => $signature) {
$signatureInfo = [];
foreach ($signature as $key => $value) {
list($label, $value) = $this->translate($key, $value);
if (!$label) {
continue;
}
$signatureInfo[$key] = ['label' => $label, 'value' => $value];
}
$data[$sigKey] = $signatureInfo;
}

return $data;
}
return $data;
}

private function signaturesInfo($file)
{
return (new PdfSig($file))->getSignature();
}
private function signaturesInfo($file) {
return (new PdfSig($file))->getSignature();
}

private function translate($key, $value)
{
switch ($key) {
case 'Signer Certificate Common Name':
return ['Nome Comum do Certificado do Assinante', $value];
case 'Signer full Distinguished Name':
return ['Nome Completo do Certificado do Assinante', $value];
case 'Signing Time':
return ['Assinado em', $value];
case 'Signing Hash Algorithm':
return ['Tipo do Algoritmo', $value];
case 'Signature Type':
return ['Tipo da assinatura', $value];
case 'Signed Ranges':
return [null, null];
case 'Total document signed':
return [null, null];
case 'Not total document signed':
return [null, null];
case 'Signature Validation':
return ['Validação da Assinatura', $this->translateSignatureValidation($value)];
case 'Certificate Validation':
return [null, null];
default:
return [$key, $value];
}
}
private function translate($key, $value) {
switch ($key) {
case 'Signer Certificate Common Name':
return ['Nome Comum do Certificado do Assinante', $value];
case 'Signer full Distinguished Name':
return ['Nome Completo do Certificado do Assinante', $value];
case 'Signing Time':
return ['Assinado em', $value];
case 'Signing Hash Algorithm':
return ['Tipo do Algoritmo', $value];
case 'Signature Type':
return ['Tipo da assinatura', $value];
case 'Signed Ranges':
return [null, null];
case 'Total document signed':
return [null, null];
case 'Not total document signed':
return [null, null];
case 'Signature Validation':
return ['Validação da Assinatura', $this->translateSignatureValidation($value)];
case 'Certificate Validation':
return [null, null];
default:
return [$key, $value];
}
}

private function translateSignatureValidation($value)
{
switch ($value) {
case 'Signature is Valid.':
return 'Assinatura válida.';
private function translateSignatureValidation($value) {
switch ($value) {
case 'Signature is Valid.':
return 'Assinatura válida.';

case 'Signature is Invalid.':
return 'Assinatura inválida.';
case 'Signature is Invalid.':
return 'Assinatura inválida.';

case 'Digest Mismatch.':
return 'Digest Mismatch.';
case 'Digest Mismatch.':
return 'Digest Mismatch.';

case "Document isn't signed or corrupted data.":
return 'Documento não está assinado ou possui dados corrompidos.';
case "Document isn't signed or corrupted data.":
return 'Documento não está assinado ou possui dados corrompidos.';

case 'Signature has not yet been verified.':
return 'Assinatura ainda não foi verificada.';
case 'Signature has not yet been verified.':
return 'Assinatura ainda não foi verificada.';

case 'Unknown Validation Failure.':
return 'Falha desconhecida na validação.';
default:
return $value;
}
}
case 'Unknown Validation Failure.':
return 'Falha desconhecida na validação.';
default:
return $value;
}
}
}
Loading