Beispiel #1
0
// Sort by encoding included tag, length, and data
//
bool asnbuf_greater(const SNACC::AsnBuf &x, const SNACC::AsnBuf &y)
{
    AsnLen len(0);
    AsnTag xTag = (BDecTag(x, len) & 0xDFFFFFFF);
    AsnTag yTag = (BDecTag(y, len) & 0xDFFFFFFF);

    x.ResetMode();
    y.ResetMode();

    return (xTag > yTag);
}
Beispiel #2
0
bool std::greater<SNACC::AsnBuf>::operator()(const SNACC::AsnBuf &x,
        const SNACC::AsnBuf &y) const
{
    AsnLen len;
    AsnTag xTag = (BDecTag(x, len) & 0xDFFFFFFF);
    AsnTag yTag = (BDecTag(y, len) & 0xDFFFFFFF);

    x.ResetMode();
    y.ResetMode();

    return (xTag > yTag);
}
Beispiel #3
0
void BDEC_2ND_EOC_OCTET(const SNACC::AsnBuf &b, SNACC::AsnLen &bytesDecoded)
{
   FUNC("BDEC_2ND_EOC_OCTET");

   if ((b.GetByte() != 0))
      throw EXCEPT("second octet of EOC not zero", DECODE_ERROR);
   
   bytesDecoded++;
}
Beispiel #4
0
void newBufTest()
{
    std::cout << "*** Testing AsnBuf ****\n";
    try {
        SNACC::AsnBuf testBufExcept;
        testBufExcept.GetByte();
    } catch (SNACC::SnaccException &e) {
        std::cout << "Caught buffer exception as expected: " << e.what()
                  << "\n";
    }

    std::fstream fs("test.txt");

    unsigned char test[10000];
    int j;
    try {
        fillTestBuffer(&test[0], 10000);

        // file test
        std::filebuf fb;
        fb.open("test.txt", std::ios_base::out | std::ios_base::binary);
        fb.sputn((char *)&test[0], 10000);
        fb.close();

        SNACC::AsnBuf fileBuf("test.txt");
        if (fileBuf.length() != 10000) {
            std::cout << "ERROR: AsnBuf() file length check failed!\n";
        } else {
            char fileData[10000];
            try {
                fileBuf.GetSeg(&fileData[0], 10000);
                if (memcmp(fileData, test, 10000) != 0) {
                    std::cout << "ERROR: AsnBuf() file data check failed!\n";
                }
            } catch(...) {
                std::cout << "ERROR: AsnBuf() file GetSeg() failed!\n";
            }
        }

        SNACC::AsnBuf buf2[1000];

        for (j = 0; j < 1; j++) {

            SNACC::AsnBuf tmpBuf((char *)test,4200);
#ifdef _DEBUG
            tmpBuf.status(std::cout);
#endif
            tmpBuf.ResetMode();
            char ch = tmpBuf.GetByte();
            char ch2 = tmpBuf.GetByte();
            std::cout << "ch == " << (int)ch
                      << " ch2 == " << (int)ch2 << "\n";

            buf2[j].PutSegRvs((char *)test, 10000);

#ifdef _DEBUG
            buf2[j].status(std::cout);
#endif
            SNACC::AsnBuf buf;
            buf = buf2[j];
            buf.ResetMode();
            if (buf.length() != 10000) {
                std::cout << "length() after PutSegRvs() test FAILED!\n";
            }

            std::stringstream ss, ss2;

            ss << buf;
            buf.ResetMode();
            ss2 << buf;

#ifdef _DEBUG
            buf.status(std::cout);
#endif
            buf.ResetMode();
            const char *ps = ss.str().data(); // buf.GetSeg(10000)

            checkTestBuffer((unsigned char *) ps, 10000);

            if ((ss.str().length() == 10000) &&
                (memcmp(test, ps, 10000) == 0)) {
                std::cout << "ss is good!" << std::endl;
            } else {
                std::cout << "[" << j << "] ss is not good!" << std::endl;
            }

            const char *ps2 = ss2.str().data();
            if (ss2.str().length() == 10000 &&
                memcmp(test, ps2, 10000) == 0){
                std::cout << "ss2 is good!" << std::endl;
            } else{
                std::cout << "[" << j << "] ss2 is not good" << std::endl;
            }
        }
    } catch (std::exception &e) {
        std::cout << "Caught Standard Exception: " << e.what() << std::endl;
    } catch (...) {
        std::cout << "Caught un-handled exception!" << std::endl;
    }

    std::cout << "*** end of AsnBuf test ***\n";
}