From fc914b727d7fbc0d080d8d989d017547080c2c25 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 24 Jun 2020 22:46:20 +1000 Subject: [PATCH] Remove to_bytes() methods --- lib/OpenPgP/CompressedDataPacket.php | 8 ++++---- lib/OpenPgP/Crypt/Symmetric.php | 2 +- lib/OpenPgP/Message.php | 11 ----------- lib/OpenPgP/S2K.php | 2 +- lib/OpenPgP/SecretKeyPacket.php | 2 +- lib/OpenPgP/SymmetricSessionKeyPacket.php | 3 +-- 6 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/OpenPgP/CompressedDataPacket.php b/lib/OpenPgP/CompressedDataPacket.php index 89ab1e9..3f28492 100644 --- a/lib/OpenPgP/CompressedDataPacket.php +++ b/lib/OpenPgP/CompressedDataPacket.php @@ -51,19 +51,19 @@ class CompressedDataPacket extends Packet implements \IteratorAggregate, \ArrayA switch($this->algorithm) { case 0: - $body .= $this->data->to_bytes(); + $body .= (string)$this->data; break; case 1: - $body .= gzdeflate($this->data->to_bytes()); + $body .= gzdeflate((string)$this->data); break; case 2: - $body .= gzcompress($this->data->to_bytes()); + $body .= gzcompress((string)$this->data); break; case 3: - $body .= bzcompress($this->data->to_bytes()); + $body .= bzcompress((string)$this->data); break; default: diff --git a/lib/OpenPgP/Crypt/Symmetric.php b/lib/OpenPgP/Crypt/Symmetric.php index 490491a..add63a9 100644 --- a/lib/OpenPgP/Crypt/Symmetric.php +++ b/lib/OpenPgP/Crypt/Symmetric.php @@ -32,7 +32,7 @@ class Symmetric $key = Random::string($key_bytes); $cipher->setKey($key); - $to_encrypt = $prefix.$message->to_bytes(); + $to_encrypt = $prefix.$message; $mdc = new OpenPGP\ModificationDetectionCodePacket(hash('sha1',$to_encrypt."\xD3\x14",true)); $to_encrypt .= (string)$mdc; diff --git a/lib/OpenPgP/Message.php b/lib/OpenPgP/Message.php index 8c7dac8..a20b9c6 100644 --- a/lib/OpenPgP/Message.php +++ b/lib/OpenPgP/Message.php @@ -198,17 +198,6 @@ class Message implements \IteratorAggregate,\ArrayAccess return $final_sigs; } - public function to_bytes(): string - { - $bytes = ''; - - foreach ($this as $p) { - $bytes .= (string)$p; - } - - return $bytes; - } - /** * Function to extract verified signatures * diff --git a/lib/OpenPgP/S2K.php b/lib/OpenPgP/S2K.php index cb9a4f1..ae52127 100644 --- a/lib/OpenPgP/S2K.php +++ b/lib/OpenPgP/S2K.php @@ -43,7 +43,7 @@ class S2K return $s2k; } - function to_bytes() + function __toString() { $bytes = chr($this->type); diff --git a/lib/OpenPgP/SecretKeyPacket.php b/lib/OpenPgP/SecretKeyPacket.php index 490dccd..d8fc27d 100644 --- a/lib/OpenPgP/SecretKeyPacket.php +++ b/lib/OpenPgP/SecretKeyPacket.php @@ -29,7 +29,7 @@ class SecretKeyPacket extends PublicKeyPacket $secret_material = NULL; if($this->s2k_useage == 255 || $this->s2k_useage == 254) { $bytes .= chr($this->symmetric_algorithm); - $bytes .= $this->s2k->to_bytes(); + $bytes .= (string)$this->s2k; } if($this->s2k_useage > 0) { $bytes .= $this->encrypted_data; diff --git a/lib/OpenPgP/SymmetricSessionKeyPacket.php b/lib/OpenPgP/SymmetricSessionKeyPacket.php index ca1418c..b36c947 100644 --- a/lib/OpenPgP/SymmetricSessionKeyPacket.php +++ b/lib/OpenPgP/SymmetricSessionKeyPacket.php @@ -23,8 +23,7 @@ class SymmetricSessionKeyPacket extends Packet function body() { - return chr($this->version) . chr($this->symmetric_algorithm) . - $this->s2k->to_bytes() . $this->encrypted_data; + return chr($this->version).chr($this->symmetric_algorithm).$this->s2k.$this->encrypted_data; } function read()