aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/pgp/inline.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/pgp/inline.py')
-rw-r--r--src/mailman_pgp/pgp/inline.py54
1 files changed, 42 insertions, 12 deletions
diff --git a/src/mailman_pgp/pgp/inline.py b/src/mailman_pgp/pgp/inline.py
index 0ed5926..2eb6d43 100644
--- a/src/mailman_pgp/pgp/inline.py
+++ b/src/mailman_pgp/pgp/inline.py
@@ -15,24 +15,54 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
-""""""
+"""Strict inline PGP message wrapper."""
from email.message import Message
-from pgpy import PGPMessage
+from pgpy import PGPKey, PGPMessage
+from pgpy.types import Armorable
class PGPInlineWrapper:
def __init__(self, msg: Message):
self.msg = msg
- self.pgp = None
- if not msg.is_multipart():
- try:
- self.pgp = PGPMessage.from_blob(msg.get_payload())
- except:
- pass
- def is_inline_signed(self):
- return self.pgp is not None and self.pgp.is_signed
+ def _is_inline(self):
+ return not self.msg.is_multipart()
- def is_inline_encrypted(self):
- return self.pgp is not None and self.pgp.is_encrypted
+ def _as_string(self):
+ return str(self.msg.get_payload())
+
+ def _has_armor(self, block_type):
+ try:
+ dearm = Armorable.ascii_unarmor(self._as_string())
+ if dearm['magic'] == block_type:
+ return True
+ except:
+ pass
+ return False
+
+ def is_signed(self):
+ """
+
+ :return:
+ """
+ return self._is_inline() and self._has_armor('SIGNATURE')
+
+ def is_encrypted(self):
+ """
+
+ :return:
+ """
+ return self._is_inline() and self._has_armor('MESSAGE')
+
+ def verify(self, key: PGPKey):
+ """
+
+ :param key:
+ :return:
+ """
+ message = PGPMessage.from_blob(self._as_string())
+ return key.verify(message)
+
+ def decrypt(self, key: PGPKey):
+ pass