fix: rm unused headers of paper key
This commit is contained in:
parent
b384411156
commit
f813e3b71e
@ -16,16 +16,14 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#ifdef _WIN32
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include "output.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#include "packets.h"
|
||||
|
||||
extern unsigned int output_width;
|
||||
@ -331,14 +329,4 @@ void output_end() {
|
||||
}
|
||||
}
|
||||
|
||||
void set_binary_mode(FILE *stream) {
|
||||
#ifdef _WIN32
|
||||
if (_setmode(_fileno(stream), _O_BINARY) == -1) {
|
||||
fprintf(stderr, "Unable to set stream mode to binary: %s\n",
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
(void)stream;
|
||||
#endif
|
||||
}
|
||||
void set_binary_mode(FILE *stream) { (void)stream; }
|
@ -18,9 +18,9 @@
|
||||
|
||||
#include "packets.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "GFSDKBasic.h"
|
||||
#include "output.h"
|
||||
|
@ -16,17 +16,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "extract.h"
|
||||
#include "output.h"
|
||||
|
||||
int verbose = 0, ignore_crc_error = 0;
|
||||
unsigned int output_width = 78;
|
||||
char *comment = nullptr;
|
||||
@ -46,42 +35,3 @@ enum options {
|
||||
OPT_FILE_FORMAT,
|
||||
OPT_COMMENT
|
||||
};
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, NULL, OPT_HELP},
|
||||
{"version", no_argument, NULL, OPT_VERSION},
|
||||
{"verbose", no_argument, NULL, OPT_VERBOSE},
|
||||
{"output", required_argument, NULL, OPT_OUTPUT},
|
||||
{"input-type", required_argument, NULL, OPT_INPUT_TYPE},
|
||||
{"output-type", required_argument, NULL, OPT_OUTPUT_TYPE},
|
||||
{"output-width", required_argument, NULL, OPT_OUTPUT_WIDTH},
|
||||
{"secret-key", required_argument, NULL, OPT_SECRET_KEY},
|
||||
{"pubring", required_argument, NULL, OPT_PUBRING},
|
||||
{"secrets", required_argument, NULL, OPT_SECRETS},
|
||||
{"ignore-crc-error", no_argument, NULL, OPT_IGNORE_CRC_ERROR},
|
||||
{"file-format", no_argument, NULL, OPT_FILE_FORMAT},
|
||||
{"comment", required_argument, NULL, OPT_COMMENT},
|
||||
{NULL, 0, NULL, 0}};
|
||||
|
||||
static void usage(void) {
|
||||
printf("Usage: paperkey [OPTIONS]\n");
|
||||
printf(" --help (-h)\n");
|
||||
printf(" --version (-V)\n");
|
||||
printf(" --verbose (-v) be more verbose\n");
|
||||
printf(" --output (-o) write output to this file\n");
|
||||
printf(" --input-type auto, base16 or raw (binary)\n");
|
||||
printf(" --output-type base16 or raw (binary)\n");
|
||||
printf(" --output-width maximum width of base16 output\n");
|
||||
printf(
|
||||
" --secret-key"
|
||||
" extract secret data from this secret key\n");
|
||||
printf(
|
||||
" --pubring"
|
||||
" public keyring to find non-secret data\n");
|
||||
printf(
|
||||
" --secrets file containing secret"
|
||||
" data to join with the public key\n");
|
||||
printf(" --ignore-crc-error don't reject corrupted input\n");
|
||||
printf(" --file-format show the paperkey file format\n");
|
||||
printf(" --comment add a comment to the base16 output\n");
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "parse.h"
|
||||
|
||||
#include <qcryptographichash.h>
|
||||
#include <qdatastream.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@ -32,142 +31,6 @@
|
||||
extern int verbose;
|
||||
extern int ignore_crc_error;
|
||||
|
||||
struct packet *parse2(QDataStream &stream, unsigned char want,
|
||||
unsigned char stop) {
|
||||
int byte;
|
||||
struct packet *packet = NULL;
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
stream >> byte;
|
||||
|
||||
unsigned char type;
|
||||
unsigned int length;
|
||||
|
||||
if ((byte & 0x80) != 0) {
|
||||
int tmp;
|
||||
|
||||
type = byte & 0x3F;
|
||||
|
||||
/* Old-style packet type */
|
||||
if (!(byte & 0x40)) type >>= 2;
|
||||
|
||||
if (type == stop) {
|
||||
stream << byte;
|
||||
break;
|
||||
}
|
||||
|
||||
if (byte & 0x40) {
|
||||
/* New-style packets */
|
||||
stream >> byte;
|
||||
if (byte == EOF) goto fail;
|
||||
|
||||
if (byte == 255) {
|
||||
/* 4-byte length */
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length = tmp << 24;
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length |= tmp << 16;
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length |= tmp << 8;
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length |= tmp;
|
||||
} else if (byte >= 224) {
|
||||
/* Partial body length, so fail (keys can't use
|
||||
partial body) */
|
||||
fprintf(stderr, "Invalid partial packet encoding\n");
|
||||
goto fail;
|
||||
} else if (byte >= 192) {
|
||||
/* 2-byte length */
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length = ((byte - 192) << 8) + tmp + 192;
|
||||
} else
|
||||
length = byte;
|
||||
} else {
|
||||
/* Old-style packets */
|
||||
switch (byte & 0x03) {
|
||||
case 0:
|
||||
/* 1-byte length */
|
||||
stream >> byte;
|
||||
if (byte == EOF) goto fail;
|
||||
length = byte;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
/* 2-byte length */
|
||||
stream >> byte;
|
||||
if (byte == EOF) goto fail;
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length = byte << 8;
|
||||
length |= tmp;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
/* 4-byte length */
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length = tmp << 24;
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length |= tmp << 16;
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length |= tmp << 8;
|
||||
stream >> tmp;
|
||||
if (tmp == EOF) goto fail;
|
||||
length |= tmp;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Error: unable to parse old-style length\n");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose > 1)
|
||||
fprintf(stderr, "Found packet of type %d, length %d\n", type, length);
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Error: unable to parse OpenPGP packets"
|
||||
" (is this armored data?)\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (want == 0 || type == want) {
|
||||
packet =
|
||||
static_cast<struct packet *>(GFAllocateMemory(sizeof(struct packet)));
|
||||
packet->type = type;
|
||||
packet->buf = static_cast<unsigned char *>(GFAllocateMemory(length));
|
||||
packet->len = length;
|
||||
packet->size = length;
|
||||
if (stream.readRawData(reinterpret_cast<char *>(packet->buf),
|
||||
packet->len) < packet->len) {
|
||||
fprintf(stderr, "Short read on packet type %d\n", type);
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
/* We don't want it, so skip the packet. We don't use fseek
|
||||
here since the input might be on stdin and that isn't
|
||||
seekable. */
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < length; i++) stream >> byte;
|
||||
}
|
||||
}
|
||||
|
||||
return packet;
|
||||
|
||||
fail:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct packet *parse(FILE *input, unsigned char want, unsigned char stop) {
|
||||
int byte;
|
||||
struct packet *packet = NULL;
|
||||
|
@ -18,16 +18,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <qstring.h>
|
||||
|
||||
#include "output.h"
|
||||
|
||||
auto parse(FILE *input, unsigned char want,
|
||||
unsigned char stop) -> struct packet *;
|
||||
|
||||
struct packet *parse2(QDataStream &stream, unsigned char want,
|
||||
unsigned char stop);
|
||||
|
||||
auto calculate_fingerprint(struct packet *packet, size_t public_len,
|
||||
unsigned char fingerprint[20]) -> int;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user