key.rb 919 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module SecureMailing::PGP::Tool::Key
  3. extend ActiveSupport::Concern
  4. include SecureMailing::PGP::Tool::Exec
  5. included do
  6. def import(key)
  7. gpg('import', stdin: key)
  8. end
  9. def export(fingerprint, passphrase = nil, secret: false)
  10. options = %w[
  11. --export-options export-minimal
  12. --armor
  13. ]
  14. command = secret ? 'export-secret-key' : 'export'
  15. result = gpg(command, options: options, arguments: [fingerprint], passphrase: passphrase)
  16. return result if result.stdout.present?
  17. error_export!(result.stderr, secret)
  18. result
  19. end
  20. def passphrase(fingerprint, passphrase)
  21. options = %w[--dry-run]
  22. result = gpg('passwd', options: options, arguments: [fingerprint], passphrase: passphrase)
  23. error_passphrase!(result.stderr)
  24. result
  25. end
  26. end
  27. end