diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-02-22 19:20:42 +0300 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 16:40:41 +0300 |
commit | e34cef0cd2fcf9a01d3f3b6dd215bbcc25d65d27 (patch) | |
tree | c9d1bbda57acec6f41b740488366654ca3892676 /lib/gitlab | |
parent | 7b4d29f4b5b02b5aee3e3cbfc8282965a38c4622 (diff) |
extract gpg functionality to lib class
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/gpg.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb new file mode 100644 index 00000000000..373ef79ab85 --- /dev/null +++ b/lib/gitlab/gpg.rb @@ -0,0 +1,32 @@ +module Gitlab + module Gpg + extend self + + def fingerprints_from_key(key) + using_tmp_keychain do + import = GPGME::Key.import(key) + + return [] if import.imported == 0 + + import.imports.map(&:fingerprint) + end + end + + def using_tmp_keychain + Dir.mktmpdir do |dir| + @original_dirs ||= [GPGME::Engine.dirinfo('homedir')] + @original_dirs.push(dir) + + GPGME::Engine.home_dir = dir + + return_value = yield + + @original_dirs.pop + + GPGME::Engine.home_dir = @original_dirs[-1] + + return_value + end + end + end +end |