示例#1
0
bool AsnBuf::operator<(const AsnBuf &rhs) const
{
   bool lessThan = true;
   bool firstTime = true;
   ResetMode();
   rhs.ResetMode();
   std::streambuf::int_type ch1;
   std::streambuf::int_type ch2;
   while ( lessThan )
   {
      try
      {
         ch1 = GetUByte();
      }
      catch (BufferException &)
      {
         ch1 = EOF;
      }

      try
      {
         ch2 = rhs.GetUByte();
      }
      catch (BufferException &)
      {
         ch2 = EOF;
      }

      if ((ch1 == EOF) && (ch2 == EOF))
      {
         if (firstTime)
            lessThan = false;
         break;
      } 
      else if (ch2 == EOF)
      {
         lessThan = false;
         break;
      }
      else if (ch1 == EOF)
      {
         break;
      }

      if (ch1 > ch2)
         lessThan = false;
      else if (ch1 < ch2)
         break;

      firstTime = false;
   }
   ResetMode();
   rhs.ResetMode();
   return lessThan;
}
示例#2
0
void TestSetSorting(void)
{
   int i = 0;
   while (gSetSortingTable[i].input != NULL)
   {
      AsnLen bytesDecoded=0, bytesEncoded;
      //TestSetSorting1 testSetSorting1;
      int ch;

      std::string input, result;
      
      hex2str(gSetSortingTable[i].input, input);
      hex2str(gSetSortingTable[i].derSorted, result);
     
      std::stringstream ssInput(input);
      std::stringstream ssResult(result);
      
      AsnBuf inputBuf(ssInput);
      AsnBuf expectedResultBuf(ssResult);
      AsnBuf outputBuf;

      inputBuf.ResetMode();
      expectedResultBuf.ResetMode();

      gSetSortingTable[i].asnType->BDec(inputBuf, bytesDecoded);
      bytesEncoded = gSetSortingTable[i].asnType->BEnc(outputBuf);
      if (bytesEncoded != bytesDecoded)
      {
         std::cout << "Encoded / Decode byte length mismatch!!!\n";
      }
      
      if (outputBuf == expectedResultBuf)
      {
         std::cout << "SET sorting SUCCESS!\n";
      }
      else
      {

         std::cout << "SET sorting FAILURE!\n";
         std::string str;
         std::cout << "Expected result: ";
         expectedResultBuf.hexDump(std::cout);
         std::cout << std::endl;
         std::cout << "Actual result  : ";
         outputBuf.ResetMode();
         outputBuf.hexDump(std::cout);

         std::cout << std::endl;
      }
      i++;
   }
   multiCardSetTest();
}
示例#3
0
bool AsnBuf::operator == (const AsnBuf &b) const
{
   bool equal = true;
   ResetMode();
   b.ResetMode();
   std::streambuf::int_type ch1;
   std::streambuf::int_type ch2;
   while ( equal )
   {
      try
      {
         ch1 = GetUByte();
      }
      catch (BufferException &)
      {
         ch1 = EOF;
      }

      try
      {
         ch2 = b.GetUByte();
      }
      catch (BufferException &)
      {
         ch2 = EOF;
      }

      if ((ch1 == EOF) && (ch1 == EOF))
         break;

      if (ch1 != ch2)
         equal = false;
   }
   ResetMode();
   b.ResetMode();
   return equal;
}
示例#4
0
void multiCardSetTest()
{
   OctetStringSetOf octsSet;
   unsigned char test[10213];
   fillTestBuffer(test,10213);

   octsSet.insert(octsSet.end(), SNACC::AsnOcts())->Set((char*)test, 10213);

   std::cout << "**** LARGE SET OF OCTET STRING TEST ****\n";

   AsnBuf tmpBuf;
   AsnLen bytesEncoded = octsSet.BEnc(tmpBuf);
   checkBuf(tmpBuf);
   AsnLen bytesDecoded = 0;
   std::stringstream ss;
   ss << tmpBuf;
   

   OctetStringSetOf octsSet2;
   tmpBuf.ResetMode();
   octsSet2.BDec(tmpBuf, bytesDecoded);

   if (bytesEncoded != bytesDecoded)
   {
      std::cout << "Bytes encoded/decoded do not match\n";
   }

   if (checkTestBuffer(octsSet2.front().c_ustr(), octsSet2.front().Len()))
   {
      std::cout << "SUCCESS!\n";
   }
   else
   {
      std::cout << "FAILURE!\n";
   }

   std::cout << "**** END OF LARGE SET OF OCTET STRING TEST ****\n";
}