Commit ad01fbde by Enrico Pozzobon

modified linux template to allow nocrypt

parent 6a6c6617
...@@ -34,7 +34,7 @@ unsigned long long nplen = NPUB_LENGTH; ...@@ -34,7 +34,7 @@ unsigned long long nplen = NPUB_LENGTH;
unsigned char *k = NULL; unsigned char *k = NULL;
unsigned long long klen = KEY_LENGTH; unsigned long long klen = KEY_LENGTH;
static void read_variable(unsigned char **target, unsigned long long *lenp) { static void recv_variable(unsigned char **target, unsigned long long *lenp) {
if (*target != NULL) { if (*target != NULL) {
free(*target); free(*target);
} }
...@@ -46,26 +46,25 @@ static void read_variable(unsigned char **target, unsigned long long *lenp) { ...@@ -46,26 +46,25 @@ static void read_variable(unsigned char **target, unsigned long long *lenp) {
} }
*lenp = len; *lenp = len;
if (*lenp == 0) { *target = malloc(len);
*target = NULL;
return;
}
*target = malloc(*lenp);
if (NULL == *target) { if (NULL == *target) {
fprintf(stderr, "ERROR: couldn't malloc %llu bytes\r\n", *lenp); fprintf(stderr, "ERROR: couldn't malloc %u bytes\r\n", len);
exit(2); exit(2);
} }
if (*lenp == 0) {
return;
}
if (1 != fread(*target, *lenp, 1, stdin)) { if (1 != fread(*target, *lenp, 1, stdin)) {
fprintf(stderr, "ERROR: didn't read %llu bytes of data\r\n", *lenp); fprintf(stderr, "ERROR: didn't read %u bytes of data\r\n", len);
exit(1); exit(1);
} }
} }
static void write_variable(unsigned char *target, unsigned long long len) { static void send_variable(unsigned char *target, unsigned long long len) {
uint32_t olen = len; uint32_t olen = len;
if (1 != fwrite(&olen, sizeof(olen), 1, stdout)) { if (1 != fwrite(&olen, sizeof(olen), 1, stdout)) {
fprintf(stderr, "ERROR: didn't write length\r\n"); fprintf(stderr, "ERROR: didn't write length\r\n");
...@@ -92,22 +91,23 @@ int main() { ...@@ -92,22 +91,23 @@ int main() {
while (1) { while (1) {
if (1 != fread(&action, sizeof(action), 1, stdin)) if (1 != fread(&action, sizeof(action), 1, stdin))
return 1; return 1;
fprintf(stderr, "DEBUG: received action 0x%02x\r\n", action);
switch (action) { switch (action) {
case 'c': read_variable(&c, &clen); break; case 'c': recv_variable(&c, &clen); break;
case 'm': read_variable(&m, &mlen); break; case 'm': recv_variable(&m, &mlen); break;
case 'a': read_variable(&ad, &adlen); break; case 'a': recv_variable(&ad, &adlen); break;
case 'k': read_variable(&k, &klen); break; case 'k': recv_variable(&k, &klen); break;
case 's': read_variable(&nsec, &nslen); break; case 's': recv_variable(&nsec, &nslen); break;
case 'p': read_variable(&npub, &nplen); break; case 'p': recv_variable(&npub, &nplen); break;
case 'C': write_variable(c, clen); break; case 'C': send_variable(c, clen); break;
case 'M': write_variable(m, mlen); break; case 'M': send_variable(m, mlen); break;
case 'A': write_variable(ad, adlen); break; case 'A': send_variable(ad, adlen); break;
case 'K': write_variable(k, klen); break; case 'K': send_variable(k, klen); break;
case 'S': write_variable(nsec, nslen); break; case 'S': send_variable(nsec, nslen); break;
case 'P': write_variable(npub, nplen); break; case 'P': send_variable(npub, nplen); break;
case 'e': case 'e':
...@@ -124,6 +124,7 @@ int main() { ...@@ -124,6 +124,7 @@ int main() {
fprintf(stderr, "klen = %llu\r\n", klen); fprintf(stderr, "klen = %llu\r\n", klen);
fprintf(stderr, "k = "); FPRINTF_HEX(stderr, k, klen); fprintf(stderr, "\r\n"); fprintf(stderr, "k = "); FPRINTF_HEX(stderr, k, klen); fprintf(stderr, "\r\n");
*/ */
if (k == NULL) { if (k == NULL) {
fprintf(stderr, "Missing key\r\n"); fprintf(stderr, "Missing key\r\n");
return 3; return 3;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment