2 * cryptsetup LUKS2 protobuf to image converter
4 * Copyright (C) 2022-2023 Daniel Zatovic <daniel.zatovic@gmail.com>
5 * Copyright (C) 2022-2023 Red Hat, Inc. All rights reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <google/protobuf/text_format.h>
29 #include <google/protobuf/io/zero_copy_stream_impl.h>
31 #include "proto_to_luks2_converter.h"
33 using namespace LUKS2_proto;
35 int main(int argc, char *argv[]) {
36 LUKS2_both_headers headers;
37 LUKS2ProtoConverter converter;
40 std::string out_img_name;
43 std::cerr << "Usage: " << argv[0] << " <LUKS2 proto>\n";
47 fd = open(argv[1], O_RDONLY);
49 std::cerr << "Failed to open " << argv[1] << std::endl;
53 google::protobuf::io::FileInputStream fileInput(fd);
55 if (!google::protobuf::TextFormat::Parse(&fileInput, &headers)) {
56 std::cerr << "Failed to parse protobuf " << argv[1] << std::endl;
62 out_img_name = argv[1];
63 out_img_name += ".img";
65 fd = open(out_img_name.c_str(), O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC|O_TRUNC, 0644);
67 std::cerr << "Failed to open output file " << out_img_name << std::endl;
70 converter.set_write_headers_only(false);
71 converter.convert(headers, fd);