aboutsummaryrefslogtreecommitdiff
path: root/tests/openssl/driver.cxx
blob: a1d0f4e2b4e8c24bbfb52e3bb8050e173b86e800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// file      : tests/openssl/driver.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <cassert>

#ifndef __cpp_lib_modules_ts
#include <vector>
#include <iostream>
#include <iterator>
#include <system_error>
#endif

// Other includes.

#ifdef __cpp_modules_ts
#ifdef __cpp_lib_modules_ts
import std.core;
import std.io;
#endif
import butl.path;
import butl.utility;  // operator<<(ostream, exception)
import butl.openssl;
import butl.process;
import butl.fdstream; // nullfd

import butl.optional;     // @@ MOD Clang should not be necessary.
import butl.small_vector; // @@ MOD Clang should not be necessary.
#else
#include <libbutl/path.mxx>
#include <libbutl/utility.mxx>
#include <libbutl/openssl.mxx>
#include <libbutl/fdstream.mxx>
#endif

using namespace std;
using namespace butl;

// Usage: argv[0]
//
int
main (int, const char* argv[])
try
{
  openssl os (nullfd, path ("-"), 2, path ("openssl"), "rand", 128);

  vector<char> r (os.in.read_binary ());
  os.in.close ();

  return os.wait () && r.size () == 128 ? 0 : 1;
}
catch (const system_error& e)
{
  cerr << argv[0] << ": " << e << endl;
  return 1;
}