diff --git a/modules/dev/pgp-keyserver.lua b/modules/dev/pgp-keyserver.lua index a7bb193..6210534 100644 --- a/modules/dev/pgp-keyserver.lua +++ b/modules/dev/pgp-keyserver.lua @@ -40,32 +40,37 @@ function run(arg) error('http error: ' .. url .. ' => ' .. resp['status']) else pubkey = pgp_pubkey_armored(resp['text']) - -- print(pubkey) + if last_err() then + warn(last_err()) + clear_err() + else + -- print(pubkey) - emails = {} - domain_matched = false + local emails = {} + local domain_matched = false - -- TODO: ensure at least one email matches our target domain - if pubkey['uids'] then - for j=1, #pubkey['uids'] do - local m = regex_find("(.+) <([^< ]+@[^< ]+)>$", pubkey['uids'][j]) - if m then - local email = m[3]:lower() - emails[#emails+1] = { - value=email, - displayname=m[2], - } + -- TODO: ensure at least one email matches our target domain + if pubkey['uids'] then + for j=1, #pubkey['uids'] do + local m = regex_find("(.+) <([^< ]+@[^< ]+)>$", pubkey['uids'][j]) + if m then + local email = m[3]:lower() + emails[#emails+1] = { + value=email, + displayname=m[2], + } - if email:match('@' .. domain .. '$') then - domain_matched = true + if email:match('@' .. domain .. '$') then + domain_matched = true + end end end end - end - if domain_matched then - for j=1, #emails do - db_add('email', emails[j]) + if domain_matched then + for j=1, #emails do + db_add('email', emails[j]) + end end end end diff --git a/modules/harness/pgp-stdin.lua b/modules/harness/pgp-stdin.lua new file mode 100644 index 0000000..75beb08 --- /dev/null +++ b/modules/harness/pgp-stdin.lua @@ -0,0 +1,9 @@ +-- Description: Decode armored pgp key from stdin +-- Version: 0.1.0 +-- License: GPL-3.0 + +function run() + local pubkey = stdin_read_to_end() + pubkey = pgp_pubkey_armored(pubkey) + info(pubkey) +end diff --git a/src/runtime/pgp.rs b/src/runtime/pgp.rs index a863e38..ce5c81e 100644 --- a/src/runtime/pgp.rs +++ b/src/runtime/pgp.rs @@ -40,8 +40,9 @@ fn pgp_pubkey_lua(pubkey: &[u8]) -> Result { fingerprint = Some(fp); }, Tag::UserID => { - let body = String::from_utf8(body)?; - uids.push_str(body); + if let Ok(body) = String::from_utf8(body) { + uids.push_str(body); + } }, Tag::Signature => { if let Ok(sig) = sloppy_rfc4880::signature::parse(&body) {