def GPGME.decrypt(cipher, *args_options)
raise ArgumentError, 'wrong number of arguments' if args_options.length > 2
args, options = split_args(args_options)
plain = args[0]
check_version(options)
GPGME::Ctx.new(options) do |ctx|
cipher_data = input_data(cipher)
plain_data = output_data(plain)
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
unless plain
plain_data.seek(0, IO::SEEK_SET)
plain_data.read
end
end
end