+
+error:
+ dict_destroy (dict);
+ fh_unref (output_fh);
+ fh_unref (input_fh);
+ fh_done ();
+ i18n_done ();
+
+ return 1;
+}
+
+static bool
+decrypt_file (struct encrypted_file *enc,
+ const struct file_handle *ifh,
+ const struct file_handle *ofh,
+ const char *password)
+{
+ FILE *out;
+ int err;
+ const char *input_filename = fh_get_file_name (ifh);
+ const char *output_filename = fh_get_file_name (ofh);
+
+ if (password == NULL)
+ {
+ password = getpass ("password: ");
+ if (password == NULL)
+ return false;
+ }
+
+ if (!encrypted_file_unlock (enc, password))
+ error (1, 0, _("sorry, wrong password"));
+
+ out = fn_open (ofh, "wb");
+ if (out == NULL)
+ error (1, errno, ("%s: error opening output file"), output_filename);
+
+ for (;;)
+ {
+ uint8_t buffer[1024];
+ size_t n;
+
+ n = encrypted_file_read (enc, buffer, sizeof buffer);
+ if (n == 0)
+ break;
+
+ if (fwrite (buffer, 1, n, out) != n)
+ error (1, errno, ("%s: write error"), output_filename);
+ }
+
+ err = encrypted_file_close (enc);
+ if (err)
+ error (1, err, ("%s: read error"), input_filename);
+
+ if (fflush (out) == EOF)
+ error (1, errno, ("%s: write error"), output_filename);
+ fn_close (ofh, out);
+
+ return true;