diff options
Diffstat (limited to 'libbutl/openssl.cxx')
-rw-r--r-- | libbutl/openssl.cxx | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/libbutl/openssl.cxx b/libbutl/openssl.cxx index 89cf8ed..48b0c1d 100644 --- a/libbutl/openssl.cxx +++ b/libbutl/openssl.cxx @@ -36,21 +36,24 @@ using namespace std; namespace butl { - int openssl:: + process::pipe openssl:: map_in (nullfd_t, io_data& d) { d.pipe.in = fdnull (); // /dev/null - return d.pipe.in.get (); + return pipe (d.pipe); } - int openssl:: + process::pipe openssl:: map_in (const path& f, io_data& d) { + pipe r; if (f.string () == "-") { // Note: no need for any options, openssl reads from stdin by default. // d.pipe = fdopen_pipe (fdopen_mode::binary); + r = pipe (d.pipe); + out.open (move (d.pipe.out)); } else @@ -58,12 +61,13 @@ namespace butl d.options.push_back ("-in"); d.options.push_back (f.string ().c_str ()); d.pipe.in = fdnull (); // /dev/null + r = pipe (d.pipe); } - return d.pipe.in.get (); + return r; } - int openssl:: + process::pipe openssl:: map_in (fdstream_mode m, io_data& d) { assert (m == fdstream_mode::text || m == fdstream_mode::binary); @@ -73,26 +77,30 @@ namespace butl d.pipe = fdopen_pipe (m == fdstream_mode::binary ? fdopen_mode::binary : fdopen_mode::none); - + pipe r (d.pipe); + out.open (move (d.pipe.out)); - return d.pipe.in.get (); + return r; } - int openssl:: + process::pipe openssl:: map_out (nullfd_t, io_data& d) { d.pipe.out = fdnull (); - return d.pipe.out.get (); // /dev/null + return pipe (d.pipe); // /dev/null } - int openssl:: + process::pipe openssl:: map_out (const path& f, io_data& d) { + pipe r; if (f.string () == "-") { // Note: no need for any options, openssl writes to stdout by default. // d.pipe = fdopen_pipe (fdopen_mode::binary); + r = pipe (d.pipe); + in.open (move (d.pipe.in), fdstream_mode::skip); } else @@ -100,12 +108,13 @@ namespace butl d.options.push_back ("-out"); d.options.push_back (f.string ().c_str ()); d.pipe.out = fdnull (); // /dev/null + r = pipe (d.pipe); } - return d.pipe.out.get (); + return r; } - int openssl:: + process::pipe openssl:: map_out (fdstream_mode m, io_data& d) { assert (m == fdstream_mode::text || m == fdstream_mode::binary); @@ -115,8 +124,9 @@ namespace butl d.pipe = fdopen_pipe (m == fdstream_mode::binary ? fdopen_mode::binary : fdopen_mode::none); - + pipe r (d.pipe); + in.open (move (d.pipe.in), fdstream_mode::skip); - return d.pipe.out.get (); + return r; } } |