clean up PKCS7 comments
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c0e61c21f0
commit
d0e4d03e96
1 changed files with 24 additions and 0 deletions
|
@ -38,25 +38,43 @@ class PKCS7 extends OpenSSL\C\CBackedObjectWithOwner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a DER representation of this PKCS7
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function toDER(): string
|
public function toDER(): string
|
||||||
{
|
{
|
||||||
|
// Create NULL uint8_t*
|
||||||
$buf = $this->ffi->new("uint8_t*");
|
$buf = $this->ffi->new("uint8_t*");
|
||||||
|
// Get pointer from it (ptr being now uint8_t**)
|
||||||
$ptr = FFI::addr($buf);
|
$ptr = FFI::addr($buf);
|
||||||
|
// Give NULL pointer to OpenSSL and let it fill it up
|
||||||
$len = $this->ffi->i2d_PKCS7($this->cObj, $ptr);
|
$len = $this->ffi->i2d_PKCS7($this->cObj, $ptr);
|
||||||
if ($len < 0) {
|
if ($len < 0) {
|
||||||
throw new \RuntimeException("Failed to create DER from PKCS7 object");
|
throw new \RuntimeException("Failed to create DER from PKCS7 object");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read string from pointer
|
||||||
$val = FFI::string($buf, $len);
|
$val = FFI::string($buf, $len);
|
||||||
|
// Free buffer via CRYPTO_free as OpenSSL malloc'd it
|
||||||
$this->ffi->CRYPTO_free($buf);
|
$this->ffi->CRYPTO_free($buf);
|
||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function freeObject()
|
public function freeObject()
|
||||||
{
|
{
|
||||||
$this->ffi->PKCS7_free($this->cObj);
|
$this->ffi->PKCS7_free($this->cObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new PKCS7
|
||||||
|
*
|
||||||
|
* @return PKCS7
|
||||||
|
*/
|
||||||
public static function new(): PKCS7
|
public static function new(): PKCS7
|
||||||
{
|
{
|
||||||
$ffi = OpenSSL::getFFI();
|
$ffi = OpenSSL::getFFI();
|
||||||
|
@ -64,6 +82,12 @@ class PKCS7 extends OpenSSL\C\CBackedObjectWithOwner
|
||||||
return new PKCS7($ffi, $cObj);
|
return new PKCS7($ffi, $cObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a PKCS7 object from DER
|
||||||
|
*
|
||||||
|
* @param string $der The string containing the DER
|
||||||
|
* @return PKCS7
|
||||||
|
*/
|
||||||
public static function loadFromDER(string $der): PKCS7
|
public static function loadFromDER(string $der): PKCS7
|
||||||
{
|
{
|
||||||
$ffi = OpenSSL::getFFI();
|
$ffi = OpenSSL::getFFI();
|
||||||
|
|
Loading…
Reference in a new issue