|
@@ -20,34 +20,36 @@ int rgpgfs_gpgme_get_encrypt_key(gpgme_ctx_t gpgme_ctx, const char *key_name,
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-int rgpgfs_gpgme_data_to_file(const char *path, gpgme_data_t data) {
|
|
|
|
- if (gpgme_data_seek(data, 0, SEEK_SET) != 0) {
|
|
|
|
- perror("rgpgfs_gpgme_data_to_file: failed to seek");
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- FILE *file = fopen(path, "wb");
|
|
|
|
- if (file == NULL) {
|
|
|
|
- perror("rgpgfs_gpgme_data_to_file: failed to open file");
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+static int _rgpgfs_gpgme_write_data_to_file(FILE *file, gpgme_data_t data) {
|
|
ssize_t count;
|
|
ssize_t count;
|
|
char buf[BUFSIZ];
|
|
char buf[BUFSIZ];
|
|
while ((count = gpgme_data_read(data, buf, BUFSIZ)) > 0) {
|
|
while ((count = gpgme_data_read(data, buf, BUFSIZ)) > 0) {
|
|
if (fwrite(buf, 1, count, file) != count) {
|
|
if (fwrite(buf, 1, count, file) != count) {
|
|
- fprintf(stderr,
|
|
|
|
- "rgpgfs_gpgme_data_to_file: failed to write data to file");
|
|
|
|
|
|
+ fprintf(stderr, "%s: failed to write data to file", __func__);
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (count != 0) {
|
|
if (count != 0) {
|
|
- perror("rgpgfs_gpgme_data_to_file: failed to load data into buffer");
|
|
|
|
|
|
+ perror("_rgpgfs_gpgme_write_data_to_file: failed to load data into buffer");
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int rgpgfs_gpgme_data_to_file(const char *path, gpgme_data_t data) {
|
|
|
|
+ if (gpgme_data_seek(data, 0, SEEK_SET) != 0) {
|
|
|
|
+ perror("rgpgfs_gpgme_data_to_file: failed to seek");
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ FILE *file = fopen(path, "wb");
|
|
|
|
+ if (file == NULL) {
|
|
|
|
+ perror("rgpgfs_gpgme_data_to_file: failed to open file");
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ int res = _rgpgfs_gpgme_write_data_to_file(file, data);
|
|
fclose(file);
|
|
fclose(file);
|
|
- return 0;
|
|
|
|
|
|
+ return res;
|
|
}
|
|
}
|
|
|
|
|
|
int rgpgfs_gpgme_encrypt_data_to_file(gpgme_ctx_t gpgme_ctx,
|
|
int rgpgfs_gpgme_encrypt_data_to_file(gpgme_ctx_t gpgme_ctx,
|