]> git.draconx.ca Git - homepage.git/commitdiff
Ensure ASCII-armoured keyrings are text items.
authorNick Bowler <nbowler@draconx.ca>
Sat, 26 Mar 2022 13:52:09 +0000 (09:52 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sat, 26 Mar 2022 13:52:09 +0000 (09:52 -0400)
The gzip postprocess rule only applies to text items, so the
ASCII-armoured keyring is not compressed.

It does not seem possible to produce both binary and text items from a
filter depending on options, so we split the filter into two: one for
the binary export required by WKD and the other for the armoured export
for manual download.

Rules
lib/gpg-wkd.rb

diff --git a/Rules b/Rules
index 7acf71db99c727cf4afc93c38f0c4f7f1a89fc2e..c753c3867415af50d3e5ffc6eb3049e9b7a47d5f 100644 (file)
--- a/Rules
+++ b/Rules
@@ -219,7 +219,7 @@ compile '/**/*.scss' do
 end
 
 compile '/gpg/*' do
 end
 
 compile '/gpg/*' do
-    filter :wkd_export, armor: true
+    filter :wkd_export_armor
     write "/pubring/" + @item.identifier.components.last + ".asc"
 end
 
     write "/pubring/" + @item.identifier.components.last + ".asc"
 end
 
index c6e5fccb7ba4a6a21e6af75adf8f1f00ac9bcb71..589369838817c34c2d75c92ed0270c8ea5d566e1 100644 (file)
@@ -26,13 +26,26 @@ module WKD
     def WKD.wksclient; @@wksclient end
     def WKD.wksclient=(x); @@wksclient = x end
 
     def WKD.wksclient; @@wksclient end
     def WKD.wksclient=(x); @@wksclient = x end
 
+    # Convert a list of keyring filenames into GPG keyring arguments
+    def WKD.keyring_args(args)
+        return [ "--no-default-keyring",
+            *args.map { |x| "--keyring=" + (x['/'] ? x : "./" + x) } ]
+    end
+
+    # Helper for implementing export filters below
+    def WKD.export(item, uid, *args)
+        data, result = Open3.capture2(@@gpg2, "--export", *args,
+            *WKD.keyring_args(item[:keyrings]), uid.chomp)
+        raise "gpg failed" unless result.success?
+        return data
+    end
+
     # Return a list list of all UIDs known from the given GPG keyrings.
     def WKD.uids_from_keyrings(*args)
         uids = {}
 
         Open3.popen2(@@gpg2,
     # Return a list list of all UIDs known from the given GPG keyrings.
     def WKD.uids_from_keyrings(*args)
         uids = {}
 
         Open3.popen2(@@gpg2,
-            "--no-default-keyring", "--with-colons", "--list-keys",
-            *args.map { |x| "--keyring=" + (x['/'] ? x : "./" + x) }
+            "--with-colons", "--list-keys", *WKD.keyring_args(args)
         ) do |stdin, stdout, result|
             stdin.close
             stdout.each do |line|
         ) do |stdin, stdout, result|
             stdin.close
             stdout.each do |line|
@@ -118,14 +131,16 @@ class WKDExport < Nanoc::Filter
     type :text => :binary
 
     def run(content, params = {})
     type :text => :binary
 
     def run(content, params = {})
-        args = @item[:keyrings].map { |x|
-            "--keyring=" + (x['/'] ? x : "./" + x)
-        };
-        args.append("--armor") if params[:armor]
-
-        dummy, result = Open3.capture2(WKD.gpg2, "--export",
-            "--no-default-keyring", "--output=" + output_filename,
-            *args, content.chomp)
-        raise "gpg failed" unless result.success?
+        WKD.export(item, content, "--output=" + output_filename)
+    end
+end
+
+class WKDExportArmor < Nanoc::Filter
+    identifier :wkd_export_armor
+    type :text
+
+    def run(content, params = {})
+        data = WKD.export(item, content, "--armor")
+        return data
     end
 end
     end
 end