]> Kevux Git Server - kevux-tools/commitdiff
Progress: Continue adding GPGME support.
authorKevin Day <Kevin@kevux.org>
Wed, 14 Jan 2026 04:47:19 +0000 (22:47 -0600)
committerKevin Day <Kevin@kevux.org>
Wed, 14 Jan 2026 04:47:19 +0000 (22:47 -0600)
I don't like a lot of things about GPGME, so do not enable it by default.

I'm still uncertain how I want to structure the encryption support with gpgme.
I plan on considering other encryption and checksum algorithms/libraries.

For now just create an encrypt send step file.
This is highly subject to change.

This adds a new header called "encrypt" that will explicitly designate the encryption method used.

17 files changed:
data/build/tacocat/settings
sources/c/program/kevux/tools/tacocat/main/common/define.h
sources/c/program/kevux/tools/tacocat/main/common/string.c
sources/c/program/kevux/tools/tacocat/main/common/string.h
sources/c/program/kevux/tools/tacocat/main/common/type.c
sources/c/program/kevux/tools/tacocat/main/common/type.h
sources/c/program/kevux/tools/tacocat/main/gpgme.c
sources/c/program/kevux/tools/tacocat/main/packet.c
sources/c/program/kevux/tools/tacocat/main/print/gpgme.c
sources/c/program/kevux/tools/tacocat/main/print/gpgme.h
sources/c/program/kevux/tools/tacocat/main/process.c
sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.c [new file with mode: 0644]
sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.h [new file with mode: 0644]
sources/c/program/kevux/tools/tacocat/main/send/step/file.c
sources/c/program/kevux/tools/tacocat/main/send/step/packet.c
sources/c/program/kevux/tools/tacocat/main/send/step/size.c
sources/c/program/kevux/tools/tacocat/main/tacocat.h

index ded54bcba1dba8e3a866ff8cf5e5f3b2691dca01..21628a7fa0ae8433fa7d9a282c7d5575c7b689b7 100644 (file)
@@ -31,7 +31,7 @@ version_file micro
 version_target minor
 
 modes android clang coverage debug fanalyzer flex_arrays gcc gpgme individual individual_thread level monolithic pinephone test thread threadless
-modes_default debug gcc gpgme monolithic thread
+modes_default debug gcc monolithic thread
 
 build_compiler gcc
 build_compiler-clang clang
@@ -61,7 +61,7 @@ build_sources_headers common.h common/define.h common/enumeration.h common/strin
 build_sources_headers print/error.h print/message.h print/verbose.h print/warning.h
 build_sources_headers packet.h process.h receive.h send.h signal.h tacocat.h thread.h
 build_sources_headers receive/step/check.h receive/step/control.h receive/step/done.h receive/step/extract.h receive/step/find.h receive/step/next.h receive/step/packet.h receive/step/write.h
-build_sources_headers send/step/build.h send/step/check.h send/step/done.h send/step/encode.h send/step/file.h send/step/header.h send/step/packet.h send/step/size.h send/step/wait.h
+build_sources_headers send/step/build.h send/step/check.h send/step/done.h send/step/encode.h send/step/encrypt.h send/step/file.h send/step/header.h send/step/packet.h send/step/size.h send/step/wait.h
 
 build_sources_headers-gpgme gpgme.h print/gpgme.h
 
@@ -69,7 +69,7 @@ build_sources_library common.c common/define.c common/enumeration.c common/strin
 build_sources_library print/error.c print/message.c print/verbose.c print/warning.c
 build_sources_library packet.c process.c receive.c send.c signal.c tacocat.c thread.c
 build_sources_library receive/step/check.c receive/step/control.c receive/step/done.c receive/step/extract.c receive/step/find.c receive/step/next.c receive/step/packet.c receive/step/write.c
-build_sources_library send/step/build.c send/step/check.c send/step/done.c send/step/encode.c send/step/file.c send/step/header.c send/step/packet.c send/step/size.c send/step/wait.c
+build_sources_library send/step/build.c send/step/check.c send/step/done.c send/step/encode.c send/step/encrypt.c send/step/file.c send/step/header.c send/step/packet.c send/step/size.c send/step/wait.c
 
 build_sources_library-gpgme gpgme.c print/gpgme.c
 
index 98bc7eef98fc67a114934c5411e2af73642a8fea..a98e064dd60b2c5bfaff2b3987a6b2a88d01c722 100644 (file)
@@ -72,7 +72,7 @@ extern "C" {
   #define kt_tacocat_max_buffer_d   0x10000000 // 0x10^0x5 * 0x100 (Which is 256 Megabytes (0x10^0x5 where the base unit is 16 rather than 10 or 2 (maybe call this xytes? Megaxytes?)).
   #define kt_tacocat_max_maintain_d 0x100000   // 0x10^5 (Which is 1 Megabyte in base 16 (1 Megaxyte (MX)).
 
-  #define kt_tacocat_packet_headers_d   0x9
+  #define kt_tacocat_packet_headers_d   0xb
   #define kt_tacocat_packet_id_length_d 0x20
   #define kt_tacocat_packet_minimum_d   0x11
   #define kt_tacocat_packet_peek_d      0x40
index f0c3337d80b381b437a79f3877043035fea88763..196d1305a095e24551b45ea579b112ff65a25da8 100644 (file)
@@ -17,8 +17,10 @@ extern "C" {
   const f_string_static_t kt_tacocat_classic_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_classic_s, KT_TACOCAT_classic_s_length);
   const f_string_static_t kt_tacocat_digit_negative_one_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_digit_negative_one_s, KT_TACOCAT_digit_negative_one_s_length);
   const f_string_static_t kt_tacocat_done_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_done_s, KT_TACOCAT_done_s_length);
-  const f_string_static_t kt_tacocat_kevux_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_kevux_s, KT_TACOCAT_kevux_s_length);
+  const f_string_static_t kt_tacocat_encrypt_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_encrypt_s, KT_TACOCAT_encrypt_s_length);
   const f_string_static_t kt_tacocat_file_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_file_s, KT_TACOCAT_file_s_length);
+  const f_string_static_t kt_tacocat_gpgme_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_gpgme_s, KT_TACOCAT_gpgme_s_length);
+  const f_string_static_t kt_tacocat_kevux_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_kevux_s, KT_TACOCAT_kevux_s_length);
   const f_string_static_t kt_tacocat_network_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_network_s, KT_TACOCAT_network_s_length);
   const f_string_static_t kt_tacocat_network_or_socket_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_network_or_socket_s, KT_TACOCAT_network_or_socket_s_length);
   const f_string_static_t kt_tacocat_next_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_next_s, KT_TACOCAT_next_s_length);
index 4589f8b91c2c3904bef974d168181203d6e69a94..d81a32dd2ba698d8d270ca9cc2b0eb48c5ec3098 100644 (file)
@@ -70,7 +70,9 @@ extern "C" {
   #define KT_TACOCAT_classic_s            "classic"
   #define KT_TACOCAT_digit_negative_one_s "-1"
   #define KT_TACOCAT_done_s               "done"
+  #define KT_TACOCAT_encrypt_s            "encrypt"
   #define KT_TACOCAT_file_s               "file"
+  #define KT_TACOCAT_gpgme_s              "gpgme"
   #define KT_TACOCAT_kevux_s              "kevux"
   #define KT_TACOCAT_network_s            "network"
   #define KT_TACOCAT_network_or_socket_s  "network / socket"
@@ -97,10 +99,12 @@ extern "C" {
   #define KT_TACOCAT_classic_s_length            7
   #define KT_TACOCAT_digit_negative_one_s_length 2
   #define KT_TACOCAT_done_s_length               4
+  #define KT_TACOCAT_encrypt_s_length            7
   #define KT_TACOCAT_file_s_length               4
+  #define KT_TACOCAT_gpgme_s_length              5
   #define KT_TACOCAT_kevux_s_length              5
   #define KT_TACOCAT_network_s_length            7
-  #define KT_TACOCAT_network_or_socket_s_length  16
+  #define KT_TACOCAT_network_or_socket_s_length  17
   #define KT_TACOCAT_next_s_length               4
   #define KT_TACOCAT_receive_s_length            7
   #define KT_TACOCAT_receive_done_s_length       12
@@ -124,8 +128,10 @@ extern "C" {
   extern const f_string_static_t kt_tacocat_classic_s;
   extern const f_string_static_t kt_tacocat_digit_negative_one_s;
   extern const f_string_static_t kt_tacocat_done_s;
-  extern const f_string_static_t kt_tacocat_kevux_s;
+  extern const f_string_static_t kt_tacocat_encrypt_s;
   extern const f_string_static_t kt_tacocat_file_s;
+  extern const f_string_static_t kt_tacocat_gpgme_s;
+  extern const f_string_static_t kt_tacocat_kevux_s;
   extern const f_string_static_t kt_tacocat_network_s;
   extern const f_string_static_t kt_tacocat_network_or_socket_s;
   extern const f_string_static_t kt_tacocat_next_s;
index b77e389d4a71055ffd2700950449edb6a3e63dc6..52629c2ebba3b1e14d457e0d0b8d3c3e4ac3697d 100644 (file)
@@ -19,8 +19,13 @@ extern "C" {
     if (!main) return;
 
     fll_program_data_delete(&main->program);
+
     kt_tacocat_cache_delete(&main->cache);
     kt_tacocat_setting_delete(&main->setting);
+
+    #ifdef _en_gpgme_support_
+      kt_tacocat_gpgme_delete(&main->gpgme);
+    #endif // _en_gpgme_support_
   }
 #endif // _di_kt_tacocat_main_delete_
 
@@ -42,9 +47,7 @@ extern "C" {
 
     if (!gpgme) return;
 
-    gpgme_release(gpgme->control);
-
-    // @todo
+    gpgme_release(gpgme->context);
 
     gpgme->version = f_string_empty_s.string;
   }
@@ -178,6 +181,20 @@ extern "C" {
         if (array[i].headers.size) {
           f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &array[i].headers.array, &array[i].headers.used, &array[i].headers.size, &f_string_maps_delete_callback);
         }
+
+        #ifdef _en_gpgme_support_
+          if (array[i].encrypt_read) {
+            gpgme_data_release(array[i].encrypt_read);
+
+            array[i].encrypt_read = 0;
+          }
+
+          if (array[i].encrypt_write) {
+            gpgme_data_release(array[i].encrypt_write);
+
+            array[i].encrypt_write = 0;
+          }
+        #endif // _en_gpgme_support_
       } // for
     }
 
index 5f9c1447b85069ea2db32f3bb67cd23351cc0f50..f48f2f76b9218ae166336df35968b5b85ae1b6d8 100644 (file)
@@ -76,6 +76,9 @@ extern "C" {
  *
  *   - abstruses: The abstruse header map array, used for building the headers when sending a response.
  *   - headers:   The map of the headers after being processed for use when buulding the headers when sending a response.
+ *
+ *   - encrypt_read:  The encryption payload data, dependent on algorithm, for reading/input.
+ *   - encrypt_write: The encryption payload data, dependent on algorithm, for writing/output.
  */
 #ifndef _di_kt_tacocat_socket_set_t_
   typedef struct {
@@ -128,6 +131,14 @@ extern "C" {
 
     f_abstruse_maps_t abstruses;
     f_string_maps_t headers;
+
+    #ifdef _en_gpgme_support_
+      gpgme_data_t encrypt_read;
+      gpgme_data_t encrypt_write;
+    #else
+      uint8_t encrypt_read;
+      uint8_t encrypt_write;
+    #endif // _en_gpgme_support_
   } kt_tacocat_socket_set_t;
 
   #define kt_tacocat_socket_set_t_initialize { \
@@ -175,6 +186,8 @@ extern "C" {
     .write_state                 = fl_fss_payload_header_state_t_initialize, \
     .abstruses                   = f_abstruse_maps_t_initialize, \
     .headers                     = f_string_maps_t_initialize, \
+    .encrypt_read                = 0, \
+    .encrypt_write               = 0, \
   }
 
   #define macro_kt_tacocat_socket_set_t_initialize_1(size_block_value) { \
@@ -222,6 +235,8 @@ extern "C" {
     .write_state                 = fl_fss_payload_header_state_t_initialize, \
     .abstruses                   = f_abstruse_maps_t_initialize, \
     .headers                     = f_string_maps_t_initialize, \
+    .encrypt_read                = 0, \
+    .encrypt_write               = 0, \
   }
 
   #define macro_kt_tacocat_socket_set_t_initialize_2(size_block_value, write_state_value) { \
@@ -269,6 +284,8 @@ extern "C" {
     .write_state                 = write_state_value, \
     .abstruses                   = f_abstruse_maps_t_initialize, \
     .headers                     = f_string_maps_t_initialize, \
+    .encrypt_read                = 0, \
+    .encrypt_write               = 0, \
   }
 #endif // _di_kt_tacocat_socket_set_t_
 
@@ -442,8 +459,7 @@ extern "C" {
  * The GPGME data.
  *
  * Properties:
- *   - control: The GPGME control data.
- *   - data:    The GPGME regular data.
+ *   - context: The GPGME context data.
  *   - engine:  The GPGME engine inforrmation data.
  *   - error:   The GPGME error data.
  *
@@ -451,8 +467,7 @@ extern "C" {
  */
 #if defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_gpgme_t_)
   typedef struct {
-    gpgme_ctx_t control;
-    gpgme_data_t data;
+    gpgme_ctx_t context;
     gpgme_engine_info_t engine;
     gpgme_error_t error;
 
@@ -460,8 +475,7 @@ extern "C" {
   } kt_tacocat_gpgme_t;
 
   #define kt_tacocat_gpgme_t_initialize { \
-    .control = 0, \
-    .data    = 0, \
+    .context = 0, \
     .engine  = 0, \
     .error   = 0, \
     .version = f_string_empty_s.string, \
index d84ada4c358d610e6fb10d650e9e6c99e452c61b..457dc28c8210b63716edf82f067e3fe92d5b265e 100644 (file)
@@ -13,9 +13,9 @@ extern "C" {
 
     gpgme->version = gpgme_check_version(0);
 
-    gpgme->error = gpgme_new(&gpgme->control);
+    gpgme->error = gpgme_engine_check_version(GPGME_PROTOCOL_OPENPGP);
 
-    if (gpgme->error) {
+    if (gpgme->error != GPG_ERR_NO_ERROR) {
       main->setting.state.status = F_status_set_error(F_failure);
 
       kt_tacocat_print_gpgme_error(&main->program.error, F_status_debug_source_d);
@@ -23,9 +23,9 @@ extern "C" {
       return;
     }
 
-    gpgme->error = gpgme_engine_check_version(GPGME_PROTOCOL_OPENPGP);
+    gpgme->error = gpgme_get_engine_info(&gpgme->engine);
 
-    if (gpgme->error) {
+    if (gpgme->error != GPG_ERR_NO_ERROR) {
       main->setting.state.status = F_status_set_error(F_failure);
 
       kt_tacocat_print_gpgme_error(&main->program.error, F_status_debug_source_d);
@@ -33,6 +33,25 @@ extern "C" {
       return;
     }
 
+    gpgme->error = gpgme_new(&gpgme->context);
+
+    if (gpgme->error != GPG_ERR_NO_ERROR) {
+      main->setting.state.status = F_status_set_error(F_failure);
+
+      kt_tacocat_print_gpgme_error(&main->program.error, F_status_debug_source_d);
+
+      return;
+    }
+
+    // Enable ASCII armor.
+    gpgme_set_armor(gpgme->context, F_true);
+
+    // Disable online access.
+    gpgme_set_offline(gpgme->context, F_true);
+
+    // Is this necessary?
+    //err = gpgme_ctx_set_engine_info(ceofcontext, GPGME_PROTOCOL_OpenPGP, enginfo->file_name, enginfo->home_dir);
+
     main->setting.state.status = F_okay;
   }
 #endif // defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_gpgme_setup_)
index 48f70c2312003847d6db8ad9de966ae69c25e0ae..aeb4fa215dff2c6364c261becd55d1b33bdb45fc 100644 (file)
@@ -118,6 +118,8 @@ extern "C" {
       f_range_t_initialize,
       f_range_t_initialize,
       f_range_t_initialize,
+      f_range_t_initialize,
+      f_range_t_initialize,
     };
 
     f_status_t status = set->status = F_okay;
@@ -135,6 +137,8 @@ extern "C" {
         f_fss_payload_object_salt_s,
         f_fss_payload_object_id_s,
         f_fss_payload_object_time_s,
+        f_fss_payload_object_signature_s,
+        kt_tacocat_encrypt_s,
       };
 
       for (; i < set->objects_header.used; ++i) {
@@ -326,6 +330,10 @@ extern "C" {
       }
     }
 
+    // @todo convert signature (9).
+
+    // @todo convert encrypt (10).
+
     // Convert the length (2), part (3), total (4), and salt (6).
     {
       f_number_unsigned_t number = 0;
index 68b0a7cee74b3f73549b63d57442c74fb3e29590..e95d4c7b81a670a45838c30f4c6ff77fb5d07a1c 100644 (file)
@@ -4,7 +4,7 @@
 extern "C" {
 #endif
 
-#ifndef _di_kt_tacocat_print_gpgme_error_
+#if defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_print_gpgme_error_)
   f_status_t kt_tacocat_print_gpgme_error(fl_print_t * const print, const f_string_t debug) {
 
     if (!print || !print->custom) return F_status_set_error(F_output_not);
@@ -28,12 +28,11 @@ extern "C" {
 
     fl_print_format(".%]%r", print->to, print->context, f_string_eol_s);
 
-
     f_file_stream_unlock(print->to);
 
     return F_okay;
   }
-#endif // _di_kt_tacocat_print_gpgme_error_
+#endif // defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_print_gpgme_error_)
 
 #ifdef __cplusplus
 } // extern "C"
index e83e1605eb35104249bbba1fd452076be585dc53..f72cb19311dd61929bfaae6e92b7f5a5604a98ee 100644 (file)
@@ -40,9 +40,9 @@ extern "C" {
  *
  * @see fll_error_print()
  */
-#ifndef _di_kt_tacocat_print_gpgme_error_
+#if defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_print_gpgme_error_)
   extern f_status_t kt_tacocat_print_gpgme_error(fl_print_t * const print, const f_string_t debug);
-#endif // _di_kt_tacocat_print_gpgme_error_
+#endif // defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_print_gpgme_error_)
 
 #ifdef __cplusplus
 } // extern "C"
index 5ea2fb80fa73cae8c82de923ae27c06343c6e2ac..301b4b928df048377dbd42a38bd1e2e50982139a 100644 (file)
@@ -65,10 +65,6 @@ extern "C" {
     if (F_status_is_error_not(main->setting.state.status)) {
       main->setting.state.status = F_okay;
     }
-
-    #ifdef _en_gpgme_support_
-      kt_tacocat_gpgme_delete(&main->gpgme);
-    #endif // _en_gpgme_support_
   }
 #endif // _di_kt_tacocat_process_main_
 
@@ -128,6 +124,18 @@ extern "C" {
 
     // Index 9 is the signature.
 
+    // Index 10 is the encryption.
+    set->abstruses.array[10].key = kt_tacocat_encrypt_s;
+    set->abstruses.array[10].value.type = f_abstruse_dynamic_e;
+    set->abstruses.array[10].value.is.a_dynamic = f_string_empty_s;
+    set->abstruses.array[10].value.is.a_dynamic.size = 0;
+
+    if ((main->setting.flag & kt_tacocat_main_flag_encrypt_d) && (set->flag & kt_tacocat_socket_step_flag_send_d)) {
+      #ifdef _en_gpgme_support_
+        set->abstruses.array[10].value.is.a_dynamic = kt_tacocat_gpgme_s;
+      #endif // _en_gpgme_support_
+    }
+
     {
       long salt = 0;
 
diff --git a/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.c b/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.c
new file mode 100644 (file)
index 0000000..3a64f67
--- /dev/null
@@ -0,0 +1,109 @@
+#include "../../tacocat.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_send_step_encrypt_size_)
+  void kt_tacocat_send_step_encrypt_size(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set) {
+
+    if (!main || !set || F_status_is_error(set->status)) return;
+
+    if (set->encrypt_read) {
+      gpgme_data_release(set->encrypt_read);
+
+      set->encrypt_read = 0;
+    }
+
+    gpgme_error_t error = gpgme_data_new_from_fd(&set->encrypt_read, set->file.id);
+
+    if (error != GPG_ERR_NO_ERROR) {
+      set->status = F_status_set_error(F_memory);
+
+      kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_read_s);
+
+      return;
+    }
+
+    error = gpgme_data_set_encoding(set->encrypt_read, GPGME_DATA_ENCODING_ARMOR);
+
+    if (error != GPG_ERR_NO_ERROR) {
+      set->status = F_status_set_error(F_failure);
+
+      kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_read_s);
+
+      return;
+    }
+
+    // Total is used here to explicitly pass a pointer of off_t rather than a pointer of size_t cast to an off_t.
+    // GPGME provides no way to get the file size of the encrypted data, so load the file and determine the file size as it is loading.
+    off_t total = 0;
+    gpgme_ssize_t bytes = 1;
+
+    for (char buffer[set->file.size_read + 1]; bytes > 0 && total <= F_number_t_size_unsigned_d; total += bytes) {
+      bytes = gpgme_data_read(set->encrypt_read, buffer, set->file.size_read);
+    } // for
+
+    if (bytes == -1) {
+      set->status = F_status_set_error(F_failure);
+
+      kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_read_s);
+
+      return;
+    }
+
+    if ((f_number_unsigned_t) total > F_number_t_size_unsigned_d) {
+      set->status = F_status_set_error(F_too_large);
+
+      kt_tacocat_print_error_on_file_too_large(&main->program.error, set->name, kt_tacocat_send_s, set->network, F_number_t_size_unsigned_d, set->abstruses.array[4].value.is.a_unsigned);
+
+      return;
+    }
+
+    error = gpgme_data_rewind(set->encrypt_read);
+
+    if (error != GPG_ERR_NO_ERROR) {
+      set->status = F_status_set_error(F_failure);
+
+      kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_read_s);
+
+      return;
+    }
+
+    set->abstruses.array[3].value.is.a_unsigned = 0;
+    set->size_total = (f_number_unsigned_t) total;
+
+    if (total) {
+      if (set->size_total < set->file.size_read) {
+        set->abstruses.array[2].value.is.a_unsigned = set->size_total;
+        set->abstruses.array[4].value.is.a_unsigned = 1;
+      }
+      else {
+        set->abstruses.array[2].value.is.a_unsigned = set->file.size_read;
+        set->abstruses.array[4].value.is.a_unsigned = set->size_total / set->file.size_read;
+
+        if (set->abstruses.array[4].value.is.a_unsigned % set->file.size_read) {
+          ++set->abstruses.array[4].value.is.a_unsigned;
+        }
+      }
+    }
+    else {
+      set->abstruses.array[2].value.is.a_unsigned = set->size_total;
+      set->abstruses.array[4].value.is.a_unsigned = 1;
+    }
+  }
+#endif // defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_send_step_encrypt_size_)
+
+#if !defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_send_step_encrypt_size_)
+  void kt_tacocat_send_step_encrypt_size(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set) {
+
+    set->status = F_status_set_error(F_implement_not);
+
+    // @todo replace this with an error on encryption unsupported.
+    kt_tacocat_print_error_on(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name);
+  }
+#endif // _di_kt_tacocat_send_step_encrypt_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.h b/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.h
new file mode 100644 (file)
index 0000000..670c591
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * Kevux Tools - TacocaT
+ *
+ * Project: Kevux Tools
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Provides send step encrypt functionality.
+ *
+ * This is auto-included and should not need to be explicitly included.
+ */
+#ifndef _kt_tacocat_send_step_encrypt_h
+#define _kt_tacocat_send_step_encrypt_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Perform the size step of a send request using encryption.
+ *
+ * This prints on error.
+ *
+ * @param main
+ *   The main program and settings data.
+ *
+ *   Must not be NULL.
+ *
+ *   This does not alter main.setting.state.status, except on interrupt signal.
+ * @param set
+ *   The socket set to process.
+ *
+ *   Must not be NULL.
+ *
+ *   This alters set.status:
+ *     F_okay on success.
+ *
+ *     F_done (with error bit) on error that cannot continue, such as out of memory.
+ *     F_too_large (with error bit) on file too large.
+ *
+ *     Errors (with error bit) from: f_memory_array_increase_by()
+ *
+ *     Errors (with error bit) from: gpgme_data_new_from_fd()
+ *     Errors (with error bit) from: gpgme_data_read()
+ *     Errors (with error bit) from: gpgme_data_set_encoding()
+ *
+ * @see f_memory_array_increase_by()
+ *
+ * @see gpgme_data_new_from_fd()
+ * @see gpgme_data_read()
+ * @see gpgme_data_set_encoding()
+ */
+#ifndef _di_kt_tacocat_send_step_encrypt_size_
+  extern void kt_tacocat_send_step_encrypt_size(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set);
+#endif // _di_kt_tacocat_send_step_encrypt_size_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _kt_tacocat_send_step_encrypt_h
index ccf349717e8246ca4d99857a841f65282cedd15f..3fa7ac920a27157330770699f4a67511f9fdf105 100644 (file)
@@ -9,6 +9,8 @@ extern "C" {
 
     if (!main || !set || F_status_is_error(set->status)) return;
 
+    // @todo if (main->setting.flag & kt_tacocat_main_flag_encrypt_d) {
+
     set->status = f_string_dynamic_append(f_fss_payload_object_payload_s, &set->buffer);
 
     if (F_status_is_error_not(set->status)) {
index 1252eaa35eaecb33c1e0045b0b15480b62e55f2e..3b5a97366ca94a139c27a9a6af8a832803befd51 100644 (file)
@@ -9,30 +9,25 @@ extern "C" {
 
     if (!main || !set || F_status_is_error(set->status)) return;
 
-    {
-      size_t written = 0;
+    size_t written = 0;
 
-      {
-        const size_t original = set->socket.size_write;
+    const size_t original = set->socket.size_write;
 
-        set->socket.size_write = set->buffer.used;
+    set->socket.size_write = set->buffer.used;
 
-        set->status = f_socket_write_stream(&set->socket, f_socket_flag_signal_not_e, (void *) set->buffer.string, &written);
+    set->status = f_socket_write_stream(&set->socket, f_socket_flag_signal_not_e, (void *) set->buffer.string, &written);
 
-        set->socket.size_write = original;
+    set->socket.size_write = original;
 
-        if (F_status_is_error(set->status)) {
-          kt_tacocat_print_error_on(&main->program.error, F_status_debug_source_d, kt_tacocat_send_packet_s, set->network, set->status, set->name);
+    if (F_status_is_error(set->status)) {
+      kt_tacocat_print_error_on(&main->program.error, F_status_debug_source_d, kt_tacocat_send_packet_s, set->network, set->status, set->name);
 
-          return;
-        }
-      }
-
-      // @todo handle case when written < set->buffer.used, of which each pass. The entire buffer must be sent. May need another variable for say, set->size_process.
-
-      set->size_done += written;
+      return;
     }
 
+    // @todo handle case when written < set->buffer.used, of which each pass. The entire buffer must be sent. May need another variable for say, set->size_process.
+
+    set->size_done += written;
     set->step = kt_tacocat_socket_step_send_wait_e;
     set->status = F_okay;
   }
index 88c1735185dc878c920e458eaeb8daebdd645022..68c7fc2be0d15b22e6bce893491e38b4b36246fe 100644 (file)
@@ -13,20 +13,23 @@ extern "C" {
       set->status = f_file_open(set->name, F_file_mode_all_r_d, &set->file);
 
       if (F_status_is_error(set->status)) {
-        kt_tacocat_print_error_on_file_receive(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_open_s);
+        kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_open_s);
 
         return;
       }
     }
 
-    // Total is used here to explicitly pass a pointer of off_t rather than a pointer of size_t cast to an off_t.
-    {
+    if (main->setting.flag & kt_tacocat_main_flag_encrypt_d) {
+      kt_tacocat_send_step_encrypt_size(main, set);
+    } else {
+
+      // Total is used here to explicitly pass a pointer of off_t rather than a pointer of size_t cast to an off_t.
       off_t total = 0;
 
       set->status = f_file_size_by_id(set->file, &total);
 
       if (F_status_is_error(set->status)) {
-        kt_tacocat_print_error_on_file_receive(&main->program.error, F_status_debug_source_d, kt_tacocat_send_size_s, set->network, set->status, set->name, f_file_operation_open_s);
+        kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_size_s, set->network, set->status, set->name, f_file_operation_open_s);
 
         return;
       }
index fcc12c9ddc498ecf7c692436c16d7df5bfd378cf..2684a559532aa4ca95e3c39e2c734326035b8e72 100644 (file)
@@ -86,6 +86,7 @@
 #include <program/kevux/tools/tacocat/main/send/step/check.h>
 #include <program/kevux/tools/tacocat/main/send/step/done.h>
 #include <program/kevux/tools/tacocat/main/send/step/encode.h>
+#include <program/kevux/tools/tacocat/main/send/step/encrypt.h>
 #include <program/kevux/tools/tacocat/main/send/step/file.h>
 #include <program/kevux/tools/tacocat/main/send/step/header.h>
 #include <program/kevux/tools/tacocat/main/send/step/packet.h>