From 387e6f45dd081f927ddb3c8028bda54a17a9fe2e Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Wed, 1 Jan 2025 22:59:37 -0800 Subject: better pgp parsing --- inbox_settings.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'inbox_settings.php') diff --git a/inbox_settings.php b/inbox_settings.php index 27480bc..1a6bfdb 100644 --- a/inbox_settings.php +++ b/inbox_settings.php @@ -370,16 +370,17 @@ class inbox_settings extends rcube_plugin { $parsed_keys = []; $fingerprint = null; - $data_blob = ''; + $data_message = new OpenPGP_Message(); foreach ($parsed_data->packets as $data_packet) { if ($data_packet instanceof OpenPGP_SecretKeyPacket) throw new IllegalArgumentException('Input data contains private keys.'); if ($data_packet instanceof OpenPGP_PublicKeyPacket && !($data_packet instanceof OpenPGP_PublicSubkeyPacket)) { - $parsed_keys[] = ['fingerprint' => $fingerprint, 'data_blob' => $data_blob]; + $parsed_keys[] = [ + 'fingerprint' => $fingerprint, 'data_blob' => $data_message->to_bytes()]; $fingerprint = $data_packet->fingerprint; - $data_blob = ''; + $data_message = new OpenPGP_Message(); } else if (!($data_packet instanceof OpenPGP_UserIDPacket) && !($data_packet instanceof OpenPGP_SignaturePacket) && !($data_packet instanceof OpenPGP_PublicSubkeyPacket)) { @@ -387,11 +388,12 @@ class inbox_settings extends rcube_plugin { continue; } - $data_blob .= $data_packet->to_bytes(); + $data_message[] = $data_packet; } - if (!is_null($fingerprint) && !empty($data_blob)) { - $parsed_keys[] = ['fingerprint' => $fingerprint, 'data_blob' => $data_blob]; + if (!is_null($fingerprint) && !empty($data_message->packets)) { + $parsed_keys[] = [ + 'fingerprint' => $fingerprint, 'data_blob' => $data_message->to_bytes()]; } return $parsed_keys; } -- cgit v1.2.3