diff --git a/src/OpenSSL/PKCS7.php b/src/OpenSSL/PKCS7.php index bcd62db..00c16e5 100644 --- a/src/OpenSSL/PKCS7.php +++ b/src/OpenSSL/PKCS7.php @@ -30,12 +30,13 @@ class PKCS7 extends OpenSSL\C\CBackedObjectWithOwner return $this->ffi->OBJ_obj2nid($this->cObj->type); } - public function verify(string $plain): bool + public function toSigned(): PKCS7\Signed { - $type = $this->getType(); - if (!in_array($type, [PKCS7::NID_DIGEST, self::NID_SIGNED, self::NID_SIGNED_AND_ENVELOPED])) { - throw new \RuntimeException("Can only verify signed or digested data"); + if ($this->getType() !== self::NID_SIGNED) { + throw new \RuntimeException("This PKCS7 isn't of type signed"); } + + return new PKCS7\Signed($this); } /** @@ -59,6 +60,7 @@ class PKCS7 extends OpenSSL\C\CBackedObjectWithOwner $val = FFI::string($buf, $len); // Free buffer via CRYPTO_free as OpenSSL malloc'd it $this->ffi->CRYPTO_free($buf); + return $val; } diff --git a/src/OpenSSL/PKCS7/Helpers.php b/src/OpenSSL/PKCS7/Helpers.php new file mode 100644 index 0000000..94cb73f --- /dev/null +++ b/src/OpenSSL/PKCS7/Helpers.php @@ -0,0 +1,30 @@ +pkcs7->toDER(); + } + + /** + * @return PKCS7 + */ + public function getPkcs7(): PKCS7 + { + return $this->pkcs7; + } + + public function __construct(PKCS7 $pkcs7) + { + $this->pkcs7 = $pkcs7; + } +} \ No newline at end of file diff --git a/src/OpenSSL/PKCS7/Signed.php b/src/OpenSSL/PKCS7/Signed.php new file mode 100644 index 0000000..653c6cc --- /dev/null +++ b/src/OpenSSL/PKCS7/Signed.php @@ -0,0 +1,14 @@ +