[elbe-devel] [PATCH] elbepack: egpg: implement dearmoring through gpg library

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Aug 28 07:41:37 CEST 2024


Commit 583553790eaf ("elbepack: epgp: implement dearmoring in Python")
switched the dearmoring logic to pure Python,
but the naive variant using only base64 is not enough for all keys.
Use the already used gpg library to dearmor keys instead.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/egpg.py | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/elbepack/egpg.py b/elbepack/egpg.py
index 2a5e32fdebea..5a602a0e631b 100644
--- a/elbepack/egpg.py
+++ b/elbepack/egpg.py
@@ -2,7 +2,6 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 # SPDX-FileCopyrightText: 2014-2016 Linutronix GmbH
 
-import base64
 import os
 import pathlib
 import shutil
@@ -295,8 +294,8 @@ def unarmor_openpgp_keyring(armored):
     """
     Unarmors one ascii-armored (string) OpenPGP keyring.
     """
-    b64 = armored.strip()                                              \
-                 .removeprefix('-----BEGIN PGP PUBLIC KEY BLOCK-----') \
-                 .removesuffix('-----END PGP PUBLIC KEY BLOCK-----')   \
-                 .strip()
-    return base64.b64decode(b64)
+    ctx = core.Context()
+    data = core.Data(string=armored)
+    ret = ctx.key_import(data)
+    key_id = ret.imports[0].fpr
+    return ctx.key_export(key_id)

---
base-commit: 875ed868613018af7d7544349996e93deccfcb0f
change-id: 20240828-unarmor-native-9afb74bc05aa

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh at linutronix.de>



More information about the elbe-devel mailing list