From 0e3d3d60bae48f3698f9e7b0e060edb67170b11e Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Fri, 24 Feb 2017 20:07:57 +0100 Subject: email handling for gpg keys --- lib/gitlab/gpg.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/gitlab') diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb index 64f18d00e46..73a4b691cff 100644 --- a/lib/gitlab/gpg.rb +++ b/lib/gitlab/gpg.rb @@ -2,6 +2,14 @@ module Gitlab module Gpg extend self + module CurrentKeyChain + extend self + + def emails(fingerprint) + GPGME::Key.find(:public, fingerprint).flat_map { |raw_key| raw_key.uids.map(&:email) } + end + end + def fingerprints_from_key(key) using_tmp_keychain do import = GPGME::Key.import(key) @@ -12,6 +20,18 @@ module Gitlab end end + def emails_from_key(key) + using_tmp_keychain do + import = GPGME::Key.import(key) + + return [] if import.imported == 0 + + fingerprints = import.imports.map(&:fingerprint) + + GPGME::Key.find(:public, fingerprints).flat_map { |raw_key| raw_key.uids.map(&:email) } + end + end + def add_to_keychain(key) GPGME::Key.import(key) end -- cgit v1.2.3