+ if (keys != NULL) {
+ result = cleankeys(keys);
+ logthing(LOGTHING_INFO, "%d keys cleaned.",
+ result);
+
+ flatten_publickey(keys,
+ &packets,
+ &list_end);
+
+ if (binary) {
+ write_openpgp_stream(stdout_putchar,
+ NULL,
+ packets);
+ } else {
+ armor_openpgp_stream(stdout_putchar,
+ NULL,
+ packets);
+ }
+ free_packet_list(packets);
+ packets = NULL;
+ }
+ } else {
+ rc = 1;
+ logthing(LOGTHING_NOTICE, "No keys read.");
+ }
+
+ if (keys != NULL) {
+ free_publickey(keys);
+ keys = NULL;
+ }
+ } 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(false);
+ if (!strcmp("index", argv[optind])) {
+ find_keys(search, keyid, ishex, fingerprint,
+ false, false);
+ } else if (!strcmp("vindex", argv[optind])) {
+ find_keys(search, keyid, ishex, fingerprint,
+ false, true);
+ } else if (!strcmp("getphoto", argv[optind])) {
+ if (!ishex) {
+ puts("Can't get a key on uid text."
+ " You must supply a keyid.");
+ } else if (fetch_key(keyid, &keys, false)) {
+ unsigned char *photo = NULL;
+ size_t length = 0;
+
+ if (getphoto(keys, 0, &photo, &length)) {
+ fwrite(photo,
+ 1,
+ length,
+ stdout);
+ }
+ free_publickey(keys);
+ keys = NULL;
+ } else {
+ puts("Key not found");
+ }
+ } else if (!strcmp("delete", argv[optind])) {
+ delete_key(getfullkeyid(keyid), false);
+ } else if (!strcmp("get", argv[optind])) {
+ if (!ishex) {
+ puts("Can't get a key on uid text."
+ " You must supply a keyid.");
+ } else if (fetch_key(keyid, &keys, false)) {
+ logthing(LOGTHING_INFO, "Got key.");
+ flatten_publickey(keys,
+ &packets,
+ &list_end);
+ free_publickey(keys);
+ armor_openpgp_stream(stdout_putchar,
+ NULL,
+ packets);
+ free_packet_list(packets);
+ packets = NULL;
+ } else {
+ puts("Key not found");
+ }
+ }
+ cleanupdb();