Browse Source

function split_pgp_file: add support for ascii exports

Fabian Peter Hammerle 2 years ago
parent
commit
1a0b188145
1 changed files with 8 additions and 2 deletions
  1. 8 2
      profile_default/startup/init.py

+ 8 - 2
profile_default/startup/init.py

@@ -28,8 +28,14 @@ def numpy_array_from_file(
 def split_pgp_file(
     path: pathlib.Path,
 ) -> typing.Iterator[typing.Union[bytearray, pgpdump.packet.Packet]]:
-    # https://datatracker.ietf.org/doc/html/rfc4880#section-4
-    bundle = pgpdump.BinaryData(path.read_bytes())
+    """
+    https://datatracker.ietf.org/doc/html/rfc4880#section-4
+    """
+    bundle_bytes = path.read_bytes()
+    if bundle_bytes.startswith(b"-----BEGIN"):
+        bundle = pgpdump.AsciiData(bundle_bytes)
+    else:
+        bundle = pgpdump.BinaryData(bundle_bytes)
     remaining_bytes = bundle.data
     for packet in bundle.packets():
         prefix, remaining_bytes = remaining_bytes.split(packet.data, maxsplit=1)