From 82bdf211d6ed693c1ab62f8757c2a1a5cabe1d47 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 2 Aug 2024 23:23:01 +0300 Subject: [PATCH] implement certificate read, parse methods --- src/Abstract/Model/Identity.php | 26 ++++++++++++++++++++++++++ src/Interface/Model/Identity.php | 10 ++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Abstract/Model/Identity.php b/src/Abstract/Model/Identity.php index cf6027b7..fffc8a23 100644 --- a/src/Abstract/Model/Identity.php +++ b/src/Abstract/Model/Identity.php @@ -74,4 +74,30 @@ abstract class Identity implements \Yggverse\Yoda\Interface\Model\Identity throw new Exception; } + + // Read certificate + public static function read( + OpenSSLCertificate|string $crt + ): OpenSSLCertificate + { + if ($result = openssl_x509_read($crt)) + { + return $result; + } + + throw new Exception; + } + + // Dump certificate + public static function parse( + OpenSSLCertificate|string $crt + ): array + { + if ($result = openssl_x509_parse($crt)) + { + return $result; + } + + throw new Exception; + } } \ No newline at end of file diff --git a/src/Interface/Model/Identity.php b/src/Interface/Model/Identity.php index 4cc06cd9..608e5900 100644 --- a/src/Interface/Model/Identity.php +++ b/src/Interface/Model/Identity.php @@ -37,4 +37,14 @@ interface Identity OpenSSLCertificate|string|null $crt = null, // self-signed int $days = self::CSR_SIGN_DAYS ): OpenSSLCertificate; + + // Read certificate + public static function read( + OpenSSLCertificate|string $crt + ): OpenSSLCertificate; + + // Dump certificate + public static function parse( + OpenSSLCertificate|string $crt + ): array; } \ No newline at end of file