Example #1
0
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";
    }
}
Example #2
0
//////////////////////////////////////////////////////////////////////////
// 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
}