pipe_io.cpp
来自「含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种Chec」· C++ 代码 · 共 81 行
CPP
81 行
/************************************************** Pipe I/O Source File ** (C) 1999-2002 The Botan Project **************************************************/#include <botan/pipe.h>#include <cstdio>#include <iostream>namespace Botan {/************************************************** Write data from a pipe into an ostream **************************************************/std::ostream& operator<<(std::ostream& stream, Pipe& pipe) { static const u32bit BUFFERSIZE = DEFAULT_BUFFERSIZE; SecureBuffer<byte, BUFFERSIZE> buffer; while(stream.good() && pipe.remaining()) { u32bit got = pipe.read(buffer, BUFFERSIZE); stream.write((char*)buffer.ptr(), got); } if(!stream.good()) throw Stream_IO_Error("Pipe output operator (iostream) has failed"); return stream; }/************************************************** Write data from a pipe into a stdio FILE **************************************************/std::FILE* operator<<(std::FILE* stream, Pipe& pipe) { static const u32bit BUFFERSIZE = DEFAULT_BUFFERSIZE; SecureBuffer<byte, BUFFERSIZE> buffer; while(!std::ferror(stream) && pipe.remaining()) { u32bit got = pipe.read(buffer, BUFFERSIZE); std::fwrite(buffer, 1, got, stream); } if(std::ferror(stream)) throw Stream_IO_Error("Pipe output operator (stdio) has failed"); return stream; }/************************************************** Read data from an istream into a pipe **************************************************/std::istream& operator>>(std::istream& stream, Pipe& pipe) { static const u32bit BUFFERSIZE = DEFAULT_BUFFERSIZE; SecureBuffer<byte, BUFFERSIZE> buffer; while(stream.good()) { stream.read((char*)buffer.ptr(), BUFFERSIZE); pipe.write(buffer, stream.gcount()); } if(stream.bad() || (stream.fail() && !stream.eof())) throw Stream_IO_Error("Pipe input operator (iostream) has failed"); return stream; }/************************************************** Read data from a stdio FILE into a pipe **************************************************/std::FILE* operator>>(std::FILE* stream, Pipe& pipe) { static const u32bit BUFFERSIZE = DEFAULT_BUFFERSIZE; SecureBuffer<byte, BUFFERSIZE> buffer; while(!std::ferror(stream) && !std::feof(stream)) { u32bit got = std::fread(buffer, 1, BUFFERSIZE, stream); pipe.write(buffer, got); } if(std::ferror(stream)) throw Stream_IO_Error("Pipe input operator (stdio) has failed"); return stream; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?