| 1447 | out << "Use - to read from standard in/write to standard out." << std::endl; |
| 1448 | } |
| 1449 | int migrate_key (int argc, const char** argv) |
| 1450 | { |
| 1451 | if (argc != 2) { |
| 1452 | std::clog << "Error: filenames not specified" << std::endl; |
| 1453 | help_migrate_key(std::clog); |
| 1454 | return 2; |
| 1455 | } |
| 1456 | |
| 1457 | const char* key_file_name = argv[0]; |
| 1458 | const char* new_key_file_name = argv[1]; |
| 1459 | Key_file key_file; |
| 1460 | |
| 1461 | try { |
| 1462 | if (std::strcmp(key_file_name, "-") == 0) { |
| 1463 | key_file.load_legacy(std::cin); |
| 1464 | } else { |
| 1465 | std::ifstream in(key_file_name, std::fstream::binary); |
| 1466 | if (!in) { |
| 1467 | std::clog << "Error: " << key_file_name << ": unable to open for reading" << std::endl; |
| 1468 | return 1; |
| 1469 | } |
| 1470 | key_file.load_legacy(in); |
| 1471 | } |
| 1472 | |
| 1473 | if (std::strcmp(new_key_file_name, "-") == 0) { |
| 1474 | key_file.store(std::cout); |
| 1475 | } else { |
| 1476 | if (!key_file.store_to_file(new_key_file_name)) { |
| 1477 | std::clog << "Error: " << new_key_file_name << ": unable to write key file" << std::endl; |
| 1478 | return 1; |
| 1479 | } |
| 1480 | } |
| 1481 | } catch (Key_file::Malformed) { |
| 1482 | std::clog << "Error: " << key_file_name << ": not a valid legacy git-crypt key file" << std::endl; |
| 1483 | return 1; |
| 1484 | } |
| 1485 | |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
| 1489 | void help_refresh (std::ostream& out) |
| 1490 | { |
no test coverage detected