Skip to content

Commit 5e1f391

Browse files
authored
Merge pull request #6 from eclipxe13/master
Maintenance targeting 1.1.1
2 parents fcb7add + 84faf83 commit 5e1f391

20 files changed

+77
-40
lines changed

.scrutinizer.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ filter:
44
- 'vendor/'
55

66
build:
7+
dependencies:
8+
override:
9+
- composer self-update --no-interaction --no-progress
10+
- composer remove squizlabs/php_codesniffer friendsofphp/php-cs-fixer phpstan/phpstan --dev --no-interaction --no-progress --no-update
11+
- composer install --no-interaction
712
nodes:
813
php:
914
tests:

.travis.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
language: php
22

33
# php compatibility
4-
php: ["7.2", "7.3", "7.4snapshot"]
5-
6-
matrix:
7-
allow_failures:
8-
- php: "7.4snapshot"
9-
10-
env:
11-
global:
12-
- PHP_CS_FIXER_FUTURE_MODE=1
13-
- PHP_CS_FIXER_IGNORE_ENV=1
4+
php: ["7.2", "7.3", "7.4"]
145

156
cache:
167
- directories:
@@ -24,7 +15,7 @@ script:
2415
- vendor/bin/php-cs-fixer fix --verbose
2516
- vendor/bin/phpcbf --colors -sp src/ tests/
2617
- vendor/bin/phpunit --testdox --verbose
27-
- vendor/bin/phpstan.phar analyse --no-progress --verbose --level max src/ tests/
18+
- vendor/bin/phpstan analyse --no-progress --verbose --level max src/ tests/
2819

2920
notifications:
3021
email: false

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ Before you can run these, be sure to `composer install` or `composer update`.
7878
vendor/bin/phpcs -sp src/ tests/
7979
vendor/bin/php-cs-fixer fix -v --dry-run
8080
vendor/bin/phpunit --coverage-text
81-
vendor/bin/phpstan.phar analyse --no-progress --level max src/ tests/
81+
vendor/bin/phpstan analyse --no-progress --level max src/ tests/
8282
```

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019 PHPCFDI
3+
Copyright (c) 2019 - 2020 PHPCFDI
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ así como de la llave pública.
2323
- La FIEL (o eFirma) es utilizada para firmar electrónicamente documentos (generalmente usando XML-SEC) y
2424
está reconocida por el gobierno mexicano como una manera de firma legal de una persona física o moral.
2525

26+
Con esta librería no es necesario convertir los archivos generados por el SAT a otro formato,
27+
se pueden utilizar tal y como el SAT los entrega.
2628

2729
## Instalación
2830

@@ -32,7 +34,6 @@ Usa [composer](https://getcomposer.org/)
3234
composer require phpcfdi/credentials
3335
```
3436

35-
3637
## Ejemplo básico de uso
3738

3839
```php
@@ -59,10 +60,8 @@ echo $certificado->rfc(), PHP_EOL; // el RFC del certificado
5960
echo $certificado->legalName(), PHP_EOL; // el nombre del propietario del certificado
6061
echo $certificado->branchName(), PHP_EOL; // el nombre de la sucursal (en CSD, en FIEL está vacía)
6162
echo $certificado->serialNumber()->bytes(), PHP_EOL; // número de serie del certificado
62-
6363
```
6464

65-
6665
## Acerca de los archivos de certificado y llave privada
6766

6867
Los archivos de certificado vienen en formato `X.509 DER` y los de llave privada en formato `PKCS#8 DER`.
@@ -75,7 +74,6 @@ a `base64`, en renglones de 64 caracteres y con cabeceras específicas para cert
7574
De esta forma, para usar el certificado `AAA010101AAA.cer` o la llave privada `AAA010101AAA.key` provistos por
7675
el SAT, no es necesario convertirlos con `openssl` y la librería los detectará correctamente.
7776

78-
7977
### Crear un objeto de certificado `Certificate`
8078

8179
El objeto `Certificate` no se creará si contiene datos no válidos.
@@ -91,7 +89,6 @@ o en las firmas XML, por este motivo, los formatos soportados para crear un obje
9189
- Si `$content` está totalmente en `base64`, se interpreta como `X.509 DER base64` y se formatea a `X.509 PEM`
9290
- En otro caso, se interpreta como formato `X.509 DER`, por lo que se formatea a `X.509 PEM`.
9391

94-
9592
### Crear un objeto de llave privada `PrivateKey`
9693

9794
El objeto `PrivateKey` no se creará si contiene datos no válidos.
@@ -118,7 +115,6 @@ Notas de tratamiento de archivos `DER`:
118115
Para entender más de los formatos de llaves privadas se puede consultar la siguiente liga:
119116
<https://github.com/kjur/jsrsasign/wiki/Tutorial-for-PKCS5-and-PKCS8-PEM-private-key-formats-differences>
120117

121-
122118
## Compatilibilidad
123119

124120
Esta librería se mantendrá compatible con al menos la versión con
@@ -127,13 +123,11 @@ Esta librería se mantendrá compatible con al menos la versión con
127123
También utilizamos [Versionado Semántico 2.0.0](https://semver.org/lang/es/) por lo que puedes usar esta librería
128124
sin temor a romper tu aplicación.
129125

130-
131126
## Contribuciones
132127

133128
Las contribuciones con bienvenidas. Por favor lee [CONTRIBUTING][] para más detalles
134129
y recuerda revisar el archivo de tareas pendientes [TODO][] y el [CHANGELOG][].
135130

136-
137131
## Copyright and License
138132

139133
The phpcfdi/finkok library is copyright © [PhpCfdi](https://github.com/phpcfdi)
@@ -146,15 +140,15 @@ and licensed for use under the MIT License (MIT). Please see [LICENSE][] for mor
146140
[source]: https://github.com/phpcfdi/credentials
147141
[release]: https://github.com/phpcfdi/credentials/releases
148142
[license]: https://github.com/phpcfdi/credentials/blob/master/LICENSE
149-
[build]: https://travis-ci.org/phpcfdi/credentials?branch=master
143+
[build]: https://travis-ci.com/phpcfdi/credentials?branch=master
150144
[quality]: https://scrutinizer-ci.com/g/phpcfdi/credentials/
151145
[coverage]: https://scrutinizer-ci.com/g/phpcfdi/credentials/code-structure/master/code-coverage/src/
152146
[downloads]: https://packagist.org/packages/phpcfdi/credentials
153147

154148
[badge-source]: https://img.shields.io/badge/source-phpcfdi/credentials-blue?style=flat-square
155149
[badge-release]: https://img.shields.io/github/release/phpcfdi/credentials?style=flat-square
156150
[badge-license]: https://img.shields.io/github/license/phpcfdi/credentials?style=flat-square
157-
[badge-build]: https://img.shields.io/travis/phpcfdi/credentials/master?style=flat-square
151+
[badge-build]: https://img.shields.io/travis/com/phpcfdi/credentials/master?style=flat-square
158152
[badge-quality]: https://img.shields.io/scrutinizer/g/phpcfdi/credentials/master?style=flat-square
159153
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/phpcfdi/credentials/master?style=flat-square
160154
[badge-downloads]: https://img.shields.io/packagist/dt/phpcfdi/credentials?style=flat-square

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"phpunit/phpunit": "^8.4",
2727
"squizlabs/php_codesniffer": "^3.0",
2828
"friendsofphp/php-cs-fixer": "^2.4",
29-
"phpstan/phpstan-shim": "^0.11"
29+
"phpstan/phpstan": "^0.12"
3030
},
3131
"autoload": {
3232
"psr-4": {

docs/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
Nos apegamos a [SEMVER](SEMVER.md), revisa la información para entender mejor el control de versiones.
88

9+
## Version 1.1.1 2020-01-22
10+
11+
- Weak Break Compatibility Change: `PemExtractor::__construct($contents)` se podría construir con un parámetro de
12+
cualquier tipo de datos y al intentar usar el objeto inevitablemente iba a generar un `TypeError`. Se cambió la
13+
firma del constructor a `PemExtractor::__construct(string $contents)`, así fallaría desde construir el objeto y
14+
no al usar cualquiera de sus métodos.
15+
- Se actualiza la licencia a 2020.
16+
- Se actualiza de `phpstan/phpstan-shim: ^0.11` a `phpstan/phpstan: ^0.12`.
17+
- Se actualiza la integración continua en Travis y Scrutinizer.
18+
919
## Version 1.1.0 2019-11-19
1020

1121
- Se puede crear una llave privada en formato `PKCS#8 DER` encriptada o desprotegida.

src/Certificate.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(string $contents)
4545
$pem = static::convertDerToPem($contents);
4646
}
4747

48-
/** @var array|false $parsed */
48+
/** @var array<mixed>|false $parsed */
4949
$parsed = openssl_x509_parse($pem, true);
5050
if (false === $parsed) {
5151
throw new UnexpectedValueException('Cannot parse X509 certificate from contents');
@@ -95,6 +95,9 @@ public function pemAsOneLine(): string
9595
return implode('', preg_grep('/^((?!-).)*$/', explode(PHP_EOL, $this->pem())));
9696
}
9797

98+
/**
99+
* @return array<mixed>
100+
*/
98101
public function parsed(): array
99102
{
100103
return $this->dataArray;
@@ -120,6 +123,7 @@ public function name(): string
120123
return $this->extractString('name');
121124
}
122125

126+
/** @return array<string, string> */
123127
public function subject(): array
124128
{
125129
return $this->extractArray('subject');
@@ -135,6 +139,7 @@ public function hash(): string
135139
return $this->extractString('hash');
136140
}
137141

142+
/** @return array<string, string> */
138143
public function issuer(): array
139144
{
140145
return $this->extractArray('issuer');
@@ -196,11 +201,13 @@ public function signatureTypeNID(): string
196201
return $this->extractString('signatureTypeNID');
197202
}
198203

204+
/** @return array<mixed> */
199205
public function purposes(): array
200206
{
201207
return $this->extractArray('purposes');
202208
}
203209

210+
/** @return array<string, string> */
204211
public function extensions(): array
205212
{
206213
return $this->extractArray('extensions');

src/Credential.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(Certificate $certificate, PrivateKey $privateKey)
3939
* @param string $certificateContents
4040
* @param string $privateKeyContents
4141
* @param string $passPhrase
42-
* @return static
42+
* @return self
4343
*/
4444
public static function create(string $certificateContents, string $privateKeyContents, string $passPhrase): self
4545
{
@@ -58,7 +58,7 @@ public static function create(string $certificateContents, string $privateKeyCon
5858
* @param string $certificateFile
5959
* @param string $privateKeyFile
6060
* @param string $passPhrase
61-
* @return static
61+
* @return self
6262
*/
6363
public static function openFiles(string $certificateFile, string $privateKeyFile, string $passPhrase): self
6464
{

src/Internal/DataArrayTrait.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
/** @internal */
1010
trait DataArrayTrait
1111
{
12-
/** @var array content of openssl_x509_parse */
12+
/** @var array<mixed> content of openssl_x509_parse or openssl_pkey_get_details */
1313
protected $dataArray;
1414

15+
/**
16+
* @param string $key
17+
* @param string|int|float|bool $default
18+
* @return string|int|float|bool
19+
*/
1520
protected function extractScalar(string $key, $default)
1621
{
1722
$value = $this->dataArray[$key] ?? $default;
@@ -35,7 +40,11 @@ protected function extractInteger(string $key): int
3540
return 0;
3641
}
3742

38-
protected function extractArray(string $key):array
43+
/**
44+
* @param string $key
45+
* @return array<mixed>
46+
*/
47+
protected function extractArray(string $key): array
3948
{
4049
$data = $this->dataArray[$key] ?? null;
4150
if (! is_array($data)) {

0 commit comments

Comments
 (0)