Exemplo n.º 1
0
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";
    }
}
Exemplo n.º 2
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";
    }
}