From da37bd9e9da585fdc382455b298739e21433c175 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sat, 26 Mar 2022 09:52:09 -0400 Subject: [PATCH] Ensure ASCII-armoured keyrings are text items. 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 | 2 +- lib/gpg-wkd.rb | 37 ++++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Rules b/Rules index 7acf71d..c753c38 100644 --- a/Rules +++ b/Rules @@ -219,7 +219,7 @@ compile '/**/*.scss' do end compile '/gpg/*' do - filter :wkd_export, armor: true + filter :wkd_export_armor write "/pubring/" + @item.identifier.components.last + ".asc" end diff --git a/lib/gpg-wkd.rb b/lib/gpg-wkd.rb index c6e5fcc..5893698 100644 --- a/lib/gpg-wkd.rb +++ b/lib/gpg-wkd.rb @@ -26,13 +26,26 @@ module WKD 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, - "--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| @@ -118,14 +131,16 @@ class WKDExport < Nanoc::Filter 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 -- 2.43.0