Added macro that indicates presence of the time callback feature. Also added C++...
[BearSSL] / tools / brssl.c
index 982dc18..91372b0 100644 (file)
 #include <stdint.h>
 #include <errno.h>
 
+/*
+ * Network stuff on Windows requires some specific code.
+ */
+#ifdef _WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#pragma comment(lib, "Ws2_32.lib")
+#endif
+
 #include "brssl.h"
-#include "bearssl.h"
 
 static void
 usage(void)
@@ -42,6 +50,8 @@ usage(void)
        fprintf(stderr, "   skey         decode private key\n");
        fprintf(stderr, "   ta           decode trust anchors\n");
        fprintf(stderr, "   chain        make C code for certificate chains\n");
+       fprintf(stderr, "   twrch        run the Twrch protocol\n");
+       fprintf(stderr, "   impl         report on implementations\n");
 }
 
 int
@@ -53,6 +63,18 @@ main(int argc, char *argv[])
                usage();
                return EXIT_FAILURE;
        }
+#ifdef _WIN32
+       {
+               WSADATA wd;
+               int r;
+
+               r = WSAStartup(MAKEWORD(2, 2), &wd);
+               if (r != 0) {
+                       fprintf(stderr, "WARNING: network initialisation"
+                               " failed (WSAStartup() returned %d)\n", r);
+               }
+       }
+#endif
        cmd = argv[1];
        if (eqstr(cmd, "client")) {
                if (do_client(argc - 2, argv + 2) < 0) {
@@ -78,6 +100,19 @@ main(int argc, char *argv[])
                if (do_chain(argc - 2, argv + 2) < 0) {
                        return EXIT_FAILURE;
                }
+       } else if (eqstr(cmd, "twrch")) {
+               int ret;
+
+               ret = do_twrch(argc - 2, argv + 2);
+               if (ret < 0) {
+                       return EXIT_FAILURE;
+               } else {
+                       return ret;
+               }
+       } else if (eqstr(cmd, "impl")) {
+               if (do_impl(argc - 2, argv + 2) < 0) {
+                       return EXIT_FAILURE;
+               }
        } else {
                fprintf(stderr, "unknown command: '%s'\n", cmd);
                usage();