소스 검색

function split_pgp_file: add support for ascii exports

Fabian Peter Hammerle 3 년 전
부모
커밋
1a0b188145
1개의 변경된 파일8개의 추가작업 그리고 2개의 파일을 삭제
  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)