+ if ((argc - optind) < 1) {
+ usage();
+ } else if (!strcmp("add", argv[optind])) {
+ if (binary) {
+ read_openpgp_stream(stdin_getchar, NULL, &packets);
+ } else {
+ dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
+ }
+ if (packets != NULL) {
+ parse_keys(packets, &keys);
+ free_packet_list(packets);
+ packets = NULL;
+ if (verbose) {
+ fprintf(stderr, "Finished reading keys.\n");
+ }
+
+ initdb();
+ fprintf(stderr, "Got %d new keys.\n",
+ update_keys(&keys, verbose));
+ cleanupdb();
+ } else {
+ rc = 1;
+ fprintf(stderr, "No keys read.\n");
+ }
+
+ if (keys != NULL) {
+ free_publickey(keys);
+ keys = NULL;
+ } else {
+ rc = 1;
+ fprintf(stderr, "No changes.\n");
+ }
+ } else if ((argc - optind) == 2) {
+ search = argv[optind+1];
+ if (search != NULL) {
+ keyid = strtoul(search, &end, 16);
+ if (*search != 0 &&
+ end != NULL &&
+ *end == 0) {
+ ishex = true;
+ }
+ }
+ initdb();
+ if (!strcmp("index", argv[optind])) {
+ find_keys(search, keyid, ishex, false, false, false);
+ } else if (!strcmp("vindex", argv[optind])) {
+ find_keys(search, keyid, ishex, false, false, true);
+ } else if (!strcmp("delete", argv[optind])) {
+ delete_key(getfullkeyid(keyid), false);
+ } else if (!strcmp("get", argv[optind])) {
+ if (fetch_key(keyid, &keys, false)) {
+ if (verbose) {
+ fprintf(stderr, "Got key.\n");
+ }
+ flatten_publickey(keys,
+ &packets,
+ &list_end);
+ armor_openpgp_stream(stdout_putchar,
+ NULL,
+ packets);
+ } else {
+ puts("Key not found");
+ }
+ }
+ cleanupdb();