Skip to content

Commit 25447cf

Browse files
Remove CFG_USERINPUTFD and use stdin replacement in affected tests.
1 parent 32149be commit 25447cf

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

src/rnp/rnpcfg.h

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,27 @@
5252
#define CFG_RECIPIENTS "recipients" /* list of encrypted data recipients */
5353
#define CFG_SIGNERS "signers" /* list of signers */
5454
#define CFG_HOMEDIR "homedir" /* home directory - folder with keyrings and so on */
55-
#define CFG_KEYFILE "keyfile" /* path to the file with key(s), used instead of keyring */
56-
#define CFG_PASSFD "pass-fd" /* password file descriptor */
57-
#define CFG_PASSWD "password" /* password as command-line constant */
58-
#define CFG_PASSWORDC "passwordc" /* number of passwords for symmetric encryption */
59-
#define CFG_USERINPUTFD "user-input-fd" /* user input file descriptor */
60-
#define CFG_NUMTRIES "numtries" /* number of password request tries, or 'unlimited' */
61-
#define CFG_EXPIRATION "expiration" /* signature expiration time */
62-
#define CFG_CREATION "creation" /* signature validity start */
63-
#define CFG_CIPHER "cipher" /* symmetric encryption algorithm as string */
64-
#define CFG_HASH "hash" /* hash algorithm used, string like 'SHA1'*/
65-
#define CFG_WEAK_HASH "weak-hash" /* allow weak algorithms */
66-
#define CFG_S2K_ITER "s2k-iter" /* number of S2K hash iterations to perform */
67-
#define CFG_S2K_MSEC "s2k-msec" /* number of milliseconds S2K should target */
68-
#define CFG_ENCRYPT_PK "encrypt_pk" /* public key should be used during encryption */
69-
#define CFG_ENCRYPT_SK "encrypt_sk" /* password encryption should be used */
70-
#define CFG_IO_RESS "ress" /* results stream */
71-
#define CFG_NUMBITS "numbits" /* number of bits in generated key */
72-
#define CFG_EXPERT "expert" /* expert key generation mode */
73-
#define CFG_ZLEVEL "zlevel" /* compression level: 0..9 (0 for no compression) */
74-
#define CFG_ZALG "zalg" /* compression algorithm: zip, zlib or bzip2 */
75-
#define CFG_AEAD "aead" /* if nonzero then AEAD enryption mode, int */
76-
#define CFG_AEAD_CHUNK "aead_chunk" /* AEAD chunk size bits, int from 0 to 56 */
55+
#define CFG_KEYFILE "keyfile" /* path to the file with key(s), used instead of keyring */
56+
#define CFG_PASSFD "pass-fd" /* password file descriptor */
57+
#define CFG_PASSWD "password" /* password as command-line constant */
58+
#define CFG_PASSWORDC "passwordc" /* number of passwords for symmetric encryption */
59+
#define CFG_NUMTRIES "numtries" /* number of password request tries, or 'unlimited' */
60+
#define CFG_EXPIRATION "expiration" /* signature expiration time */
61+
#define CFG_CREATION "creation" /* signature validity start */
62+
#define CFG_CIPHER "cipher" /* symmetric encryption algorithm as string */
63+
#define CFG_HASH "hash" /* hash algorithm used, string like 'SHA1'*/
64+
#define CFG_WEAK_HASH "weak-hash" /* allow weak algorithms */
65+
#define CFG_S2K_ITER "s2k-iter" /* number of S2K hash iterations to perform */
66+
#define CFG_S2K_MSEC "s2k-msec" /* number of milliseconds S2K should target */
67+
#define CFG_ENCRYPT_PK "encrypt_pk" /* public key should be used during encryption */
68+
#define CFG_ENCRYPT_SK "encrypt_sk" /* password encryption should be used */
69+
#define CFG_IO_RESS "ress" /* results stream */
70+
#define CFG_NUMBITS "numbits" /* number of bits in generated key */
71+
#define CFG_EXPERT "expert" /* expert key generation mode */
72+
#define CFG_ZLEVEL "zlevel" /* compression level: 0..9 (0 for no compression) */
73+
#define CFG_ZALG "zalg" /* compression algorithm: zip, zlib or bzip2 */
74+
#define CFG_AEAD "aead" /* if nonzero then AEAD enryption mode, int */
75+
#define CFG_AEAD_CHUNK "aead_chunk" /* AEAD chunk size bits, int from 0 to 56 */
7776
#define CFG_KEYSTORE_DISABLED \
7877
"disable_keystore" /* indicates whether keystore must be initialized */
7978
#define CFG_FORCE "force" /* force command to succeed operation */

src/rnpkeys/tui.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,18 +365,6 @@ cli_rnp_set_generate_params(rnp_cfg &cfg, bool subkey)
365365
cfg.set_int(CFG_KG_SUBKEY_BITS, cfg.get_int(CFG_NUMBITS));
366366
} else {
367367
FILE *input = stdin;
368-
if (cfg.has(CFG_USERINPUTFD)) {
369-
int inputfd = dup(cfg.get_int(CFG_USERINPUTFD));
370-
if (inputfd != -1) {
371-
input = rnp_fdopen(inputfd, "r");
372-
if (!input) {
373-
close(inputfd);
374-
}
375-
}
376-
}
377-
if (!input) {
378-
return false;
379-
}
380368
if (subkey) {
381369
res = rnpkeys_ask_generate_params_subkey(cfg, input);
382370
} else {

src/tests/generatekey.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ ask_expert_details(cli_rnp_t *ctx, rnp_cfg &ops, const char *rsp)
582582
bool ret = false;
583583
int pipefd[2] = {-1, -1};
584584
int user_input_pipefd[2] = {-1, -1};
585+
int saved_stdin = -1;
585586
size_t rsp_len;
586587

587588
if (pipe(pipefd) == -1) {
@@ -605,20 +606,29 @@ ask_expert_details(cli_rnp_t *ctx, rnp_cfg &ops, const char *rsp)
605606
}
606607
close(user_input_pipefd[1]);
607608

608-
/* Mock user-input*/
609-
ctx->cfg().set_int(CFG_USERINPUTFD, user_input_pipefd[0]);
609+
/* Replace stdin with our pipe */
610+
saved_stdin = dup(STDIN_FILENO);
611+
if (dup2(user_input_pipefd[0], STDIN_FILENO) == -1) {
612+
ret = false;
613+
goto end;
614+
}
610615

611616
if (!rnp_cmd(ctx, CMD_GENERATE_KEY, NULL)) {
612617
ret = false;
613618
goto end;
614619
}
620+
if (dup2(saved_stdin, STDIN_FILENO) == -1) {
621+
ret = false;
622+
goto end;
623+
}
615624
ops.copy(ctx->cfg());
616625
ret = true;
617626
end:
618627
/* Close & clean fd*/
619628
if (user_input_pipefd[0]) {
620629
close(user_input_pipefd[0]);
621630
}
631+
close(saved_stdin);
622632
return ret;
623633
}
624634

src/tests/support.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959

6060
#ifdef _WIN32
6161
#define pipe(fds) _pipe(fds, 256, O_BINARY)
62+
#define dup(fd) _dup(fd)
63+
#define dup2(fd1, fd2) _dup2(fd1, fd2)
6264
int setenv(const char *name, const char *value, int overwrite);
6365
int unsetenv(const char *name);
6466
#endif

0 commit comments

Comments
 (0)