1 /* Copyright (c) 2021, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15 #include <stdio.h>
16 #include <string>
17 #include <unistd.h>
18
19 #include <openssl/span.h>
20
21 #include "modulewrapper.h"
22
23
main()24 int main() {
25 std::unique_ptr<bssl::acvp::RequestBuffer> buffer =
26 bssl::acvp::RequestBuffer::New();
27 const bssl::acvp::ReplyCallback write_reply = std::bind(
28 bssl::acvp::WriteReplyToFd, STDOUT_FILENO, std::placeholders::_1);
29
30 for (;;) {
31 const bssl::Span<const bssl::Span<const uint8_t>> args =
32 ParseArgsFromFd(STDIN_FILENO, buffer.get());
33 if (args.empty()) {
34 return 1;
35 }
36
37 const bssl::acvp::Handler handler = bssl::acvp::FindHandler(args);
38 if (!handler) {
39 return 2;
40 }
41
42 if (!handler(args.subspan(1).data(), write_reply)) {
43 const std::string name(reinterpret_cast<const char *>(args[0].data()),
44 args[0].size());
45 fprintf(stderr, "\'%s\' operation failed.\n", name.c_str());
46 return 3;
47 }
48 }
49 };
50