⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pipe.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** Pipe Source File                               ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/pipe.h>#include <botan/secqueue.h>namespace Botan {namespace {class NullFilter : public Filter   {   public:      void write(const byte input[], u32bit length)         { send(input, length); }   };}/************************************************** Pipe Constructor                               **************************************************/Pipe::Pipe(Filter* f1, Filter* f2, Filter* f3, Filter* f4)   {   init();   append(f1);   append(f2);   append(f3);   append(f4);   }/************************************************** Pipe Constructor                               **************************************************/Pipe::Pipe(Filter* filter_array[], u32bit count)   {   init();   for(u32bit j = 0; j != count; j++)      append(filter_array[j]);   }/************************************************** Initialize the Pipe                            **************************************************/void Pipe::init()   {   pipe = 0;   default_read = 0;   locked = false;   }/************************************************** Reset the Pipe                                 **************************************************/void Pipe::reset()   {   if(locked)      throw Exception("Pipe cannot be reset while it is locked");   destruct(pipe);   pipe = 0;   locked = false;   }/************************************************** Destroy the Pipe                               **************************************************/void Pipe::destruct(Filter* to_kill)   {   if(!to_kill || dynamic_cast<SecureQueue*>(to_kill))      return;   for(u32bit j = 0; j != to_kill->total_ports(); j++)      destruct(to_kill->next[j]);   delete to_kill;   }/************************************************** Set the default read message                   **************************************************/void Pipe::set_default_msg(u32bit msg)   {   if(msg >= messages.size())      throw Invalid_Argument("Pipe::set_default_msg: msg number is too high");   default_read = msg;   }/************************************************** Start a new message                            **************************************************/void Pipe::start_msg()   {   if(locked) return;   if(pipe == 0)      pipe = new NullFilter;   find_endpoints(pipe);   pipe->new_msg();   locked = true;   }/************************************************** End the current message                        **************************************************/void Pipe::end_msg()   {   if(!locked) return;   pipe->finish_msg();   clear_endpoints(pipe);   if(dynamic_cast<NullFilter*>(pipe))      {      delete pipe;      pipe = 0;      }   locked = false;   }/************************************************** Find the endpoints of the Pipe                 **************************************************/void Pipe::find_endpoints(Filter* f)   {   for(u32bit j = 0; j != f->total_ports(); j++)      if(f->next[j] && !dynamic_cast<SecureQueue*>(f->next[j]))         find_endpoints(f->next[j]);      else         {         SecureQueue* q = new SecureQueue;         f->next[j] = q;         messages.push_back(q);         }   }/************************************************** Remove the SecureQueues attached to the Filter **************************************************/void Pipe::clear_endpoints(Filter* f)   {   if(!f) return;   for(u32bit j = 0; j != f->total_ports(); j++)      {      if(f->next[j] && dynamic_cast<SecureQueue*>(f->next[j]))         f->next[j] = 0;      if(f->next[j])         clear_endpoints(f->next[j]);      }   }/************************************************** Append a Filter to the Pipe                    **************************************************/void Pipe::append(Filter* filter)   {   if(locked)      throw Exception("Cannot append to a Pipe while it is locked");   if(!filter)      return;   if(dynamic_cast<SecureQueue*>(filter))      throw Invalid_Argument("Pipe::append: SecureQueue cannot be used");   if(!pipe) pipe = filter;   else      pipe->attach(filter);   }/************************************************** Prepend a Filter to the Pipe                   **************************************************/void Pipe::prepend(Filter* filter)   {   if(locked)      throw Exception("Cannot prepend to a Pipe while it is locked");   if(!filter)      return;   if(dynamic_cast<SecureQueue*>(filter))      throw Invalid_Argument("Pipe::prepend: SecureQueue cannot be used");   if(pipe) filter->attach(pipe);   pipe = filter;   }/************************************************** Pop a Filter off the Pipe                      **************************************************/void Pipe::pop()   {   if(locked)      throw Exception("Cannot pop off a Pipe while it is locked");   if(!pipe) return;   if(pipe->total_ports() > 1)      throw Exception("Cannot pop off a Filter with multiple ports");   Filter* f = pipe;   u32bit owns = f->owns();   pipe = pipe->next[0];   delete f;   while(owns--)      {      f = pipe;      pipe = pipe->next[0];      delete f;      }   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -