コード例 #1
0
ファイル: main.cpp プロジェクト: gregarican/esnacc-ng
void fillTest(void)
{
    unsigned char buf[] = {
        0x24, 0x80, 
            0x24, 0x80, 
                0x04, 0x01, 0xaa, 
                0x04, 0x01, 0xbb,
            0x00, 0x00, 
            0x04, 0x01, 0xcc,
            0x24, 0x80,
                0x04, 0x01, 0xdd,
                0x04, 0x01, 0xee, 
                0x24, 0x80, 
                    0x24, 0x80,
                        0x24, 0x80,
                            0x24, 0x80,
                                0x04, 0x01, 0xff,
                            0x00, 0x00,
                        0x00, 0x00,
                        0x04, 0x01, 0x11,
                    0x00, 0x00,
                0x00, 0x00,
                0x04, 0x01, 0x22,
            0x00, 0x00,
            0x04, 0x01, 0x33,
        0x00, 0x00
    };

    AsnBuf asnBuf((char *)buf, sizeof(buf));
    AsnLen len = sizeof(buf);

    AsnOcts octs;
    try {
        std::cout << "*** start of Recursive Fill tests ***\n";
        octs.BDec(asnBuf, len);

        std::cout << std::endl;

        octs.Print(std::cout);

        std::cout << std::endl; 
        std::cout << len;
        std::cout << "*** End of Recursive Fill tests ***\n";

    } catch(SnaccException &e) {
        std::cout << "Octs test failed:\n";
        std::cout << "ERROR STRING: ";
        std::cout << e.what() << "\n";
        std::cout.flush();
        std::cout << "*** End of Recursive Fill tests ***\n";
    }
}
コード例 #2
0
ファイル: asn-any.cpp プロジェクト: atigyi/esnacc-ng
AsnLen AsnAny::PEnc(AsnBufBits &b) const
{
   std::stringbuf *pbufStr=new std::stringbuf;    //MEMORY released by ~AsnBufBits.
   AsnBufBits TmpBufBits(pbufStr);
   AsnOcts tmpAnyLoadOcts;
   unsigned char *pBits;
   long lAnyBitCount, lAnyByteCount;
   unsigned long lLength=0;
   FUNC("AsnAny::PEnc()");

   if (value != NULL)    // HANDLE the case where we know the syntax.
   {
      value->PEnc(TmpBufBits);
      lAnyBitCount = TmpBufBits.length();
      pBits = TmpBufBits.GetBits(lAnyBitCount);
      lAnyByteCount = lAnyBitCount/8;
      if (lAnyByteCount*8 < lAnyBitCount)
          lAnyByteCount++;      // ZERO padded here.
      tmpAnyLoadOcts.Set((const char *)pBits, lAnyByteCount);
      delete[] pBits;
      lLength = tmpAnyLoadOcts.PEnc(b);
   }        // IF value
   else if (anyBuf != NULL)  // HANDLE the case with just a BLOB of data.
   {
       anyBuf->ResetMode();
       lLength = anyBuf->length();
       char *ptr = anyBuf->GetSeg(lLength);
       if (ptr && lLength)
       {
          tmpAnyLoadOcts.Set(ptr, lLength); // BYTE count here.
          lLength = tmpAnyLoadOcts.PEnc(b);  // BIT count returned.
       }    // END IF any data in ANY.
       delete[] ptr;
   }        // IF value/anyBuf
   else
      throw EXCEPT("Unknown any with no value", ENCODE_ERROR);

   if(pbufStr)
        delete pbufStr;

   return(lLength);
}       // END AsnAny::PEnc(...)
コード例 #3
0
ファイル: asn-any.cpp プロジェクト: atigyi/esnacc-ng
void AsnAny::PDec(AsnBufBits &b, AsnLen &bitsDecoded)
{
   AsnBufBits tmpBufBits;
   AsnOcts tmpAnyLoadOcts;
   AsnLen tmpBitsDecoded=0;
   FUNC("AsnAny::PDec");

   // ai will be NULL if this is an ANY (not an ANY DEFINED BY)
   if (ai != NULL)
   {
      // the type is already known clone it and use it's BDec to decode the 
      // ASN.1
      //
      value = ai->typeToClone->Clone();
      if (value == NULL)
      {
         throw SnaccException(STACK_ENTRY, "typeToClone->Clone() failed", INVALID_ANY);
      }     // IF value == NULL
      else
      {
         tmpAnyLoadOcts.PDec(b, bitsDecoded);  // OUTER OctetString
                                // OUTER "bitsDecoded" returned to caller.
         if (tmpAnyLoadOcts.length())
         {
             tmpBufBits.PutBits((unsigned char *)tmpAnyLoadOcts.c_ustr(), 
                            tmpAnyLoadOcts.length()*8);
             value->PDec(tmpBufBits, tmpBitsDecoded);
                                // DECODE actual known value.
         }      // END IF tmpBitsDecoded
      }     // END IF value == NULL
   }        // IF ai != NULL
   else     // JUST load BLOB of data in "anyBuf"
   {
         tmpAnyLoadOcts.PDec(b, bitsDecoded);  // OUTER OctetString
                                // OUTER "bitsDecoded" returned to caller.
         if (tmpAnyLoadOcts.length())
         {
             if(this->anyBuf)
                 delete this->anyBuf;
             this->anyBuf = new AsnBuf((char *)tmpAnyLoadOcts.c_str(), 
                                               tmpAnyLoadOcts.length());
         }  // END IF any data in ANY.
   }        // END IF ai != NULL
}           // END AsnAny::PDec(...)
コード例 #4
0
ファイル: main.cpp プロジェクト: gregarican/esnacc-ng
void doubleDecodeTest(void)
{
    char buf[] = {0x04,0x01,0x31,0x04,0x01,0x32};
    AsnBuf asnBuf(buf, 6);
    AsnLen len;
    AsnOcts octs;
    try {
        std::cout << "*** doubleDecodeTest ***\n";
        if (octs.BDecPdu(asnBuf, len)) {
            if (octs.c_ustr()[0] == '1') {
                std::cout << "First OCTET STRING value: "
                          << octs.c_ustr()[0] << std::endl;

                if (octs.BDecPdu(asnBuf, len)) {
                    if (octs.c_ustr()[0] == '2') {
                        std::cout << "Second OCTET STRING value: " 
                                  << octs.c_ustr()[0] << std::endl;
                    } else {
                        std::cout
                            << "Unexpected result for second OCTET STRING: "
                            << octs.c_ustr()[0] << std::endl;
                    }
                } else {
                    std::cout << "Decode of second OCTET STRING failed!\n";
                }
            } else {
                std::cout
                    << "ERROR: Unexpected result for first OCTET STRING: "
                    << octs.c_ustr()[0] << std::endl;
            }
        } else {
            std::cout << "Decode of double OCTET STRING encoded FAILED!\n";
        }

        std::cout << "*** doubleDecodeTest ***\n";

  } catch(SnaccException &e) {
        std::cout << "Double decode test failed:\n";
        std::cout << "ERROR STRING: ";
        std::cout << e.what() << "\n";
        std::cout.flush();
        std::cout << "*** doubleDecodeTest ***\n";
    }
}
コード例 #5
0
ファイル: sm_ContentInfo.cpp プロジェクト: dcblake/SMP
//////////////////////////////////////////////////////////////////////////
// This constructor builds a CSM_ContentInfo class from a SNACC ContentInfo
//  ASN.1 encoded Buffer (NOT CONTENT).
CSM_ContentInfoMsg::CSM_ContentInfoMsg(CSM_Buffer *pMessageBuf)
{
   CSM_Buffer ContentBuf;
   AsnOcts SNACCOcts;

   SME_SETUP("CSM_ContentInfoMsg: CSM_Buffer");

   m_pSNACCContentInfo = NULL;  // pre-initialize

   SME(SetEncodedBlob(pMessageBuf));
   
   if (pMessageBuf == NULL)
      SME_THROW(SM_MEMORY_ERROR, "pMessageBuf parameter is NULL", NULL);
   if ((m_pSNACCContentInfo = new ContentInfo) == NULL)
      SME_THROW(SM_MEMORY_ERROR, "MALLOC FAILURE", NULL);

   CSM_Buffer *pA= &ContentBuf;
   SME(DECODE_BUF(m_pSNACCContentInfo, pMessageBuf));
   SME(SM_EXTRACT_ANYBUF(pA, &m_pSNACCContentInfo->content));
   if (m_pSNACCContentInfo->contentType == id_data)    
   {               // perform decode of OCTET STRING
      DECODE_BUF(&SNACCOcts, &ContentBuf);
      ContentBuf.Set(SNACCOcts.c_str(), SNACCOcts.Len());
         
         // Only assigne Octet contents, already decoded for user.
   }
   AsnOid  tmpoid(m_pSNACCContentInfo->contentType);

   SME(SetEncapContentFromAsn1(ContentBuf, tmpoid));

   SME_FINISH
   SME_CATCH_SETUP
      if (m_pSNACCContentInfo)
          delete m_pSNACCContentInfo;
   SME_CATCH_FINISH
}
コード例 #6
0
ファイル: main.cpp プロジェクト: gregarican/esnacc-ng
void octsTest(void)
{
    unsigned char buf[] = {0x04,0x14,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
                           0x38,0x39,0x30,0x41,0x42,0x43,0x44,0x45,0x46,
                           0x47,0x48,0x49,0x50};
    AsnBuf asnBuf((char *)buf, 22);
    size_t i;
    AsnLen len = 22;

    AsnOcts octs;
    try {
        std::cout << "*** start of AsnOcts tests ***\n";
        if (octs.BDecPdu(asnBuf, len)) {
            if (memcmp(octs.c_ustr(), &buf[2], octs.Len()) == 0) {
                for (i = 0; i < 20; i++) {
                    std::cout << "OCTET STRING value: " << octs.c_ustr()[i] << std::endl;
                }
            } else {
                for (i = 0; i < 20; i++) {
                    std::cout
                        << "ERROR: Unexpected result for OCTET STRING: "
                        << octs.c_ustr()[i] << std::endl;
                }
            }
        } else {
            std::cout << "Decode of OCTET STRING encoded FAILED!\n";
        }

        std::cout << "*** End of AsnOcts tests ***\n";
    } catch(SnaccException &e) {
        std::cout << "Octs test failed:\n";
        std::cout << "ERROR STRING: ";
        std::cout << e.what() << "\n";
        std::cout.flush();
        std::cout << "*** End of AsnOcts tests ***\n";
    }
}