Browse Source

Adding import function

Adding import function to the netpgp binary, because I don't wanna
recompile the entire pEp TestEngine every time I think I fixed a bug.
master
David Lanzendörfer 12 months ago
parent
commit
84678403f5
1 changed files with 36 additions and 11 deletions
  1. +36
    -11
      src/main.c

+ 36
- 11
src/main.c View File

@ -297,7 +297,6 @@ int show_keys(netpgp_t *netpgp, prog_t *p, char *f)
int pgp_generate_keypair(netpgp_t *netpgp, prog_t *p, char *f)
{
pgp_key_t *newseckey, *newpubkey;
int result = 0;
char newid[1024];
const char *hashalg = NULL, *cipher = NULL, *username = "David Lanzendörfer", *address = "leviathan@libresilicon.com", *password = NULL;
hashalg = netpgp_getvar(netpgp, "hash");
@ -333,6 +332,38 @@ int pgp_generate_keypair(netpgp_t *netpgp, prog_t *p, char *f)
return 0;
}
int import_keydata(netpgp_t *netpgp, prog_t *p, char *f)
{
pgp_memory_t *mem;
int size;
unsigned maxsize;
char *key_data;
char *in;
mem = pgp_memory_new();
if (mem == NULL)
return 1;
if (f == NULL) {
size = stdin_to_mem(netpgp, &in, &key_data, &maxsize);
pgp_memory_add(mem, in, size);
} else {
if (!pgp_mem_readfile(mem, f)) {
pgp_memory_free(mem);
return 1;
}
}
if (pgp_keyring_read_from_mem(netpgp->io, netpgp->pubring, netpgp->secring, 1, mem) == 0) return 1;
pgp_memory_free(mem);
// save rings
if (netpgp_save_pubring(netpgp) && netpgp_save_secring(netpgp)) return 1;
return 0;
}
/* do a command once for a specified file 'f' */
static int
netpgp_cmd(netpgp_t *netpgp, prog_t *p, char *f)
@ -423,8 +454,7 @@ netpgp_cmd(netpgp_t *netpgp, prog_t *p, char *f)
p->armour);*/
return 0;
case IMPORT_KEY:
printf("Importing key\n");
return 0;
return import_keydata(netpgp,p,f);
case SHOW_KEYS:
return show_keys(netpgp,p,f);
case SHOW_SECKEYS:
@ -487,10 +517,7 @@ setoption(netpgp_t *netpgp, prog_t *p, int val, char *arg, int *homeset)
p->cmd = val;
break;
case VERSION_CMD:
printf(
"%s\nAll bug reports, praise and chocolate, please, to:\n%s\n",
pgp_get_info("version"),
pgp_get_info("maintainer"));
printf("%s\nAll bug reports, praise and chocolate, please, to:\n%s\n", pgp_get_info("version"), pgp_get_info("maintainer"));
exit(EXIT_SUCCESS);
/* options */
case KEYRING:
@ -520,8 +547,7 @@ setoption(netpgp_t *netpgp, prog_t *p, int val, char *arg, int *homeset)
break;
case HOMEDIR:
if (arg == NULL) {
(void) fprintf(stderr,
"No home directory argument provided\n");
(void) fprintf(stderr, "No home directory argument provided\n");
exit(EXIT_ERROR);
}
netpgp_set_homedir(netpgp, arg, NULL, 0);
@ -529,8 +555,7 @@ setoption(netpgp_t *netpgp, prog_t *p, int val, char *arg, int *homeset)
break;
case HASH_ALG:
if (arg == NULL) {
(void) fprintf(stderr,
"No hash algorithm argument provided\n");
(void) fprintf(stderr, "No hash algorithm argument provided\n");
exit(EXIT_ERROR);
}
netpgp_setvar(netpgp, "hash", arg);


Loading…
Cancel
Save