| 1370 | out << "When FILENAME is -, export to standard out." << std::endl; |
| 1371 | } |
| 1372 | int export_key (int argc, const char** argv) |
| 1373 | { |
| 1374 | // TODO: provide options to export only certain key versions |
| 1375 | const char* key_name = 0; |
| 1376 | Options_list options; |
| 1377 | options.push_back(Option_def("-k", &key_name)); |
| 1378 | options.push_back(Option_def("--key-name", &key_name)); |
| 1379 | |
| 1380 | int argi = parse_options(options, argc, argv); |
| 1381 | |
| 1382 | if (argc - argi != 1) { |
| 1383 | std::clog << "Error: no filename specified" << std::endl; |
| 1384 | help_export_key(std::clog); |
| 1385 | return 2; |
| 1386 | } |
| 1387 | |
| 1388 | Key_file key_file; |
| 1389 | load_key(key_file, key_name); |
| 1390 | |
| 1391 | const char* out_file_name = argv[argi]; |
| 1392 | |
| 1393 | if (std::strcmp(out_file_name, "-") == 0) { |
| 1394 | key_file.store(std::cout); |
| 1395 | } else { |
| 1396 | if (!key_file.store_to_file(out_file_name)) { |
| 1397 | std::clog << "Error: " << out_file_name << ": unable to write key file" << std::endl; |
| 1398 | return 1; |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | return 0; |
| 1403 | } |
| 1404 | |
| 1405 | void help_keygen (std::ostream& out) |
| 1406 | { |
no test coverage detected