Certificationauthority : Add phpstan @return values when parameter is null

This commit is contained in:
2022-09-09 08:34:19 +02:00
parent d7f0c2f6dd
commit 3ba6c5435a

View File

@@ -12,7 +12,6 @@ namespace Domframework;
class Certificationauthority
{
// PROPERTIES
// {{{
/** The opensslCnfPath file
*/
private $opensslCnfPath;
@@ -53,12 +52,10 @@ basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
';
// }}}
/** Check if openssl support is available in PHP
*/
public function __construct ()
// {{{
{
if (! function_exists ("openssl_csr_new"))
throw new \Exception (dgettext ("domframework",
@@ -71,17 +68,14 @@ extendedKeyUsage = serverAuth, clientAuth
"private_key_bits" => 4096,
);
}
// }}}
/** Remove the temporary files when destroying the object
*/
public function __destruct ()
// {{{
{
if (file_exists ($this->opensslCnfPath))
unlink ($this->opensslCnfPath);
}
// }}}
/** Create the pair key/cert for authority
* @param string $countryName Country name (like FR)
@@ -93,7 +87,6 @@ extendedKeyUsage = serverAuth, clientAuth
*/
public function createCA ($countryName, $organizationName, $commonName,
$days = 3650)
// {{{
{
$req_key = openssl_pkey_new (array (
"config" => $this->opensslCnfPath,
@@ -117,14 +110,12 @@ extendedKeyUsage = serverAuth, clientAuth
openssl_pkey_export ($req_key, $this->caKey);
return $this;
}
// }}}
/** Get/Set the ca cert
* @param string|null $caCert The CA cert to get/set
* @return string|self the CA if get in PEM, $this if set
* @return (string|self if caCert = null) the CA if get in PEM, $this if set
*/
public function caCert ($caCert = null)
// {{{
{
if ($caCert === null)
return $this->caCert;
@@ -133,14 +124,12 @@ extendedKeyUsage = serverAuth, clientAuth
$this->caCert = $caCert;
return $this;
}
// }}}
/** Get/Set the ca key
* @param string|null $caKey The CA key to get/set
* @return string|self the CA if get, $this if set
* @return (string|self if caKey = null) the CA if get, $this if set
*/
public function caKey ($caKey = null)
// {{{
{
if ($caKey === null)
return $this->caKey;
@@ -149,13 +138,11 @@ extendedKeyUsage = serverAuth, clientAuth
$this->caKey = $caKey;
return $this;
}
// }}}
/** Create a private key
* @return $this;
*/
public function createPrivateKey ()
// {{{
{
$this->privateKey = openssl_pkey_new (array (
"config" => $this->opensslCnfPath,
@@ -164,14 +151,12 @@ extendedKeyUsage = serverAuth, clientAuth
));
return $this;
}
// }}}
/** Get in PEM/Set the private key
* @param string|null $privateKey The private key to use
* @return string|self the privatekey if get in PEM, $this if set
* @return (string|self if $privateKey = null) the privatekey if get in PEM, $this if set
*/
public function privateKey ($privateKey = null)
// {{{
{
if ($privateKey === null)
{
@@ -184,7 +169,6 @@ extendedKeyUsage = serverAuth, clientAuth
$this->privateKey = openssl_pkey_get_private ($privateKey);
return $this;
}
// }}}
/** Create a CSR.
* Will create a private key if none is already exists
@@ -194,7 +178,6 @@ extendedKeyUsage = serverAuth, clientAuth
* @return string the CSR created in PEM
*/
public function createCSR ($countryName, $organizationName, $commonName)
// {{{
{
if ($this->privateKey === null)
$this->createPrivateKey ();
@@ -211,7 +194,6 @@ extendedKeyUsage = serverAuth, clientAuth
openssl_csr_export ($req_csr, $out);
return $out;
}
// }}}
/** Sign a CSR with an CA cert/key pair and return the signed certificate in
* PEM mode
@@ -225,7 +207,6 @@ extendedKeyUsage = serverAuth, clientAuth
*/
public function signCSR ($csr, $caCert, $caKey, $days = 365,
$altNames = array ())
// {{{
{
$conf = $this->opensslConf;
if (! empty($altNames))
@@ -256,5 +237,4 @@ extendedKeyUsage = serverAuth, clientAuth
file_put_contents ($this->opensslCnfPath, $this->opensslConf);
return $certout;
}
// }}}
}