Browse Source

z/OS support: fix read function

The function in main has been adapter for better testing
master
David Lanzendörfer 12 months ago
parent
commit
796d7be26e
1 changed files with 22 additions and 18 deletions
  1. +22
    -18
      src/main.c

+ 22
- 18
src/main.c View File

@ -332,34 +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)
/* import a key into our keyring */
int
import_key(netpgp_t *netpgp, prog_t *p, char *f)
{
pgp_memory_t *mem;
int size;
unsigned maxsize;
char *key_data;
char *in;
int size;
uint8_t* out;
uint8_t *in;
pgp_memory_t *mem;
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);
if(f==NULL) {
size = stdin_to_mem(netpgp, &in, &out, &maxsize);
pgp_memory_add(mem, in, size);
//if (pgp_keyring_read_from_mem(netpgp->io, netpgp->pubring, netpgp->secring, p->armour, mem) == 0) return 1;
pgp_keyring_read_from_mem(netpgp->io, netpgp->pubring, netpgp->secring, 1, mem);
} else {
if (!pgp_mem_readfile(mem, f)) {
pgp_memory_free(mem);
return 1;
}
//if(pgp_keyring_fileread(netpgp->io, netpgp->pubring, netpgp->secring, p->armour, f) == 0) return 1;
pgp_keyring_fileread(netpgp->io, netpgp->pubring, netpgp->secring, 1, f);
}
if (pgp_keyring_read_from_mem(netpgp->io, netpgp->pubring, netpgp->secring, 1, mem) == 0) return 1;
// save rings
if(!netpgp_save_pubring(netpgp))
fprintf(stderr, "Couln't store pubring\n");
pgp_memory_free(mem);
if(!netpgp_save_secring(netpgp))
fprintf(stderr, "Couln't store secring\n");
// save rings
if (netpgp_save_pubring(netpgp) && netpgp_save_secring(netpgp)) return 1;
pgp_memory_free(mem);
return 0;
}
@ -369,7 +373,7 @@ static int
netpgp_cmd(netpgp_t *netpgp, prog_t *p, char *f)
{
//const int cleartext = 1;
unsigned maxsize;
unsigned maxsize;
char *out;
char *in;
int ret;
@ -454,7 +458,7 @@ netpgp_cmd(netpgp_t *netpgp, prog_t *p, char *f)
p->armour);*/
return 0;
case IMPORT_KEY:
return import_keydata(netpgp,p,f);
return import_key(netpgp,p,f);
case SHOW_KEYS:
return show_keys(netpgp,p,f);
case SHOW_SECKEYS:


Loading…
Cancel
Save