class GPGME::Crypto

def decrypt(cipher, options = {})

Raises:
  • (GPGME::Error::DecryptFailed) - when the cipher was encrypted
  • (GPGME::Error::WrongKeyUsage) - TODO Don't know when
  • (GPGME::Error::UnsupportedAlgorithm) - when the cipher was encrypted

Other tags:
    Example: Verifying signatures -
    Example: Output to file -
    Example: symmetric encryption, or passwored key -
    Example: Simple decrypt -

Returns:
  • (GPGME::Data) - a {GPGME::Data} that can be read.

Parameters:
  • &block () --
  • options (Hash) --
  • cipher () --
def decrypt(cipher, options = {})
  options = @default_options.merge options
  plain_data   = Data.new(options[:output])
  cipher_data  = Data.new(cipher)
  GPGME::Ctx.new(options) do |ctx|
    begin
      ctx.decrypt_verify(cipher_data, plain_data)
    rescue GPGME::Error::UnsupportedAlgorithm => exc
      exc.algorithm = ctx.decrypt_result.unsupported_algorithm
      raise exc
    rescue GPGME::Error::WrongKeyUsage => exc
      exc.key_usage = ctx.decrypt_result.wrong_key_usage
      raise exc
    end
    verify_result = ctx.verify_result
    if verify_result && block_given?
      verify_result.signatures.each do |signature|
        yield signature
      end
    end
  end
  plain_data.seek(0)
  plain_data
end