Esempio n. 1
0
      Test::Result test_pipe_errors()
         {
         Test::Result result("Pipe");

         Botan::Pipe pipe;

         pipe.append(nullptr); // ignored
         pipe.prepend(nullptr); // ignored
         pipe.pop(); // empty pipe, so ignored

         // can't explicitly insert a queue into the pipe because they are implicit
         result.test_throws("pipe error", "Invalid argument Pipe::append: SecureQueue cannot be used",
                            [&]() { pipe.append(new Botan::SecureQueue); });
         result.test_throws("pipe error", "Invalid argument Pipe::prepend: SecureQueue cannot be used",
                            [&]() { pipe.prepend(new Botan::SecureQueue); });

         pipe.start_msg();

         // now inside a message, cannot modify pipe structure
         result.test_throws("pipe error", "Cannot append to a Pipe while it is processing",
                            [&]() { pipe.append(nullptr); });
         result.test_throws("pipe error", "Cannot prepend to a Pipe while it is processing",
                            [&]() { pipe.prepend(nullptr); });
         result.test_throws("pipe error", "Cannot pop off a Pipe while it is processing",
                            [&]() { pipe.pop(); });

         pipe.end_msg();

         pipe.append(nullptr); // ignored
         pipe.prepend(nullptr); // ignored
         pipe.pop(); // empty pipe, so ignored

         return result;
         }
Esempio n. 2
0
int main(int argc, char* argv[])
   {
   if(argc < 2)
      {
      std::cout << "Usage: " << argv[0] << " <filenames>" << std::endl;
      return 1;
      }

   Botan::LibraryInitializer init;

   // this is a pretty vacuous example, but it's useful as a test
   Botan::Pipe pipe;

   // CPS == Current Pipe Status, ie what Filters are set up

   pipe.prepend(new Botan::Hash_Filter("MD5"));
   // CPS: MD5

   pipe.prepend(new Botan::Hash_Filter("RIPEMD-160"));
   // CPS: RIPEMD-160 | MD5

   pipe.prepend(new Botan::Chain(
                   new Botan::Hash_Filter("RIPEMD-160"),
                   new Botan::Hash_Filter("RIPEMD-160")));
  // CPS: (RIPEMD-160 | RIPEMD-160) | RIPEMD-160 | MD5

   pipe.pop(); // will pop everything inside the Chain as well as Chain itself
   // CPS: RIPEMD-160 | MD5

   pipe.pop(); // will get rid of the RIPEMD-160 Hash_Filter
   // CPS: MD5

   pipe.prepend(new Botan::Hash_Filter("SHA-1"));
   // CPS: SHA-1 | MD5

   pipe.append(new Botan::Hex_Encoder);
   // CPS: SHA-1 | MD5 | Hex_Encoder

   pipe.prepend(new Botan::Hash_Filter("SHA-1"));
   // CPS: SHA-1 | SHA-1 | MD5 | Hex_Encoder

   pipe.pop(); // Get rid of the Hash_Filter(SHA-1)
   pipe.pop(); // Get rid of the other Hash_Filter(SHA-1)
   // CPS: MD5 | Hex_Encoder
       // The Hex_Encoder is safe because it is at the end of the Pipe,
       // and pop() pulls off the Filter that is at the start.

   pipe.prepend(new Botan::Hash_Filter("RIPEMD-160"));
   // CPS: RIPEMD-160 | MD5 | Hex_Encoder

   pipe.pop(); // Get rid of that last prepended Hash_Filter(RIPEMD-160)
   // CPS: MD5 | Hex_Encoder

   int skipped = 0;
   for(int j = 1; argv[j] != 0; j++)
      {
      std::ifstream file(argv[j], std::ios::binary);
      if(!file)
         {
         std::cout << "ERROR: could not open " << argv[j] << std::endl;
         skipped++;
         continue;
         }
      pipe.start_msg();
      file >> pipe;
      pipe.end_msg();
      file.close();
      pipe.set_default_msg(j-1-skipped);
      std::cout << pipe << "  " << argv[j] << std::endl;
      }
   return 0;
   }