Module: Capsium::Package::OpenPgp
- Defined in:
- lib/capsium/package/open_pgp.rb,
sig/capsium/package/open_pgp.rbs
Overview
OpenPGP support (signatures and encryption) through the rnp gem's binding to librnp. rnp is a soft dependency: it is only required when an OpenPGP feature is used, and this module is the single place that loads it.
Defined Under Namespace
Classes: KeyError, LoadedKey, OpenPgpUnavailableError
Constant Summary collapse
- UNAVAILABLE_MESSAGE =
"OpenPGP support requires librnp and the rnp gem " \ "(e.g. `brew install rnp` and `gem install rnp`)"
Class Method Summary collapse
-
.load_key(key_path, secret: false) ⇒ LoadedKey
Loads the OpenPGP key at key_path (armored or binary, public or secret — the format is auto-detected).
-
.rnp ⇒ Object
A fresh Rnp context.
Class Method Details
.load_key(key_path, secret: false) ⇒ LoadedKey
Loads the OpenPGP key at key_path (armored or binary, public or secret — the format is auto-detected). With secret: true the selected key must hold secret key material. Raises KeyError when the file is unreadable or holds no suitable key.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/capsium/package/open_pgp.rb', line 44 def self.load_key(key_path, secret: false) instance = rnp instance.load_keys(input: Rnp::Input.from_string(File.binread(key_path)), format: "GPG") key = select_key(instance, secret: secret) return LoadedKey.new(rnp: instance, key: key) if key raise KeyError, "no suitable #{secret ? 'secret' : 'public'} OpenPGP key in: #{key_path}" rescue Errno::ENOENT, Rnp::Error raise KeyError, "cannot load OpenPGP key: #{key_path}" end |
.rnp ⇒ Object
A fresh Rnp context. Raises OpenPgpUnavailableError when the rnp gem or librnp cannot be loaded.
31 32 33 34 35 36 |
# File 'lib/capsium/package/open_pgp.rb', line 31 def self.rnp require "rnp" Rnp.new rescue LoadError raise OpenPgpUnavailableError, UNAVAILABLE_MESSAGE end |