当前位置: 首页>>代码示例>>C++>>正文


C++ DataBuffer::get_data方法代码示例

本文整理汇总了C++中DataBuffer::get_data方法的典型用法代码示例。如果您正苦于以下问题:C++ DataBuffer::get_data方法的具体用法?C++ DataBuffer::get_data怎么用?C++ DataBuffer::get_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataBuffer的用法示例。


在下文中一共展示了DataBuffer::get_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: application_data

void TLSClient_Impl::application_data(DataBuffer record_plaintext)
{
    if (conversation_state != cl_tls_state_connected)
        throw Exception("Unexpected application data record received");

    int pos = recv_out_data.get_size();
    recv_out_data.set_size(pos + record_plaintext.get_size());
    memcpy(recv_out_data.get_data() + pos, record_plaintext.get_data(), record_plaintext.get_size());
}
开发者ID:eoma,项目名称:gm-engine,代码行数:9,代码来源:tls_client_impl.cpp

示例2:

void TestApp::test_aes128()
{
    Console::write_line(" Header: aes128_encrypt.h and aes128_decrypt.h");
    Console::write_line("  Class: AES128_Encrypt and AES128_Decrypt");

    // Test data from http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
    // and http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CBC.pdf

    test_aes128_helper(
        "2b7e151628aed2a6abf7158809cf4f3c",	// KEY
        "000102030405060708090A0B0C0D0E0F",	// IV
        "6bc1bee22e409f96e93d7e117393172a"	// PLAINTEXT
        "ae2d8a571e03ac9c9eb76fac45af8e51"
        "30c81c46a35ce411e5fbc1191a0a52ef"
        "f69f2445df4f9b17ad2b417be66c3710",
        "7649abac8119b246cee98e9b12e9197d"  // CIPHERTEXT
        "5086cb9b507219ee95db113a917678b2"
        "73bed6b8e3c1743b7116e69e22229516"
        "3ff1caa1681fac09120eca307586e1a7"
        );
        
    const int test_data_length = 128;
    unsigned char test_data[test_data_length];
    std::vector<unsigned char> key;
    std::vector<unsigned char> iv;
    convert_ascii("2B7E151628AED2A6ABF7158809CF4F3C", key);
    convert_ascii("000102030405060708090A0B0C0D0E0F", iv);

    for (int cnt=0; cnt<test_data_length; cnt++)
    {
        test_data[cnt] = (unsigned char) cnt;

        AES128_Encrypt aes128_encrypt;
        aes128_encrypt.set_iv(&iv[0]);
        aes128_encrypt.set_key(&key[0]);
        aes128_encrypt.add(test_data, cnt+1);
        aes128_encrypt.calculate();

        AES128_Decrypt aes128_decrypt;
        aes128_decrypt.set_iv(&iv[0]);
        aes128_decrypt.set_key(&key[0]);
        DataBuffer buffer = aes128_encrypt.get_data();
        aes128_decrypt.add(buffer.get_data(), buffer.get_size());
        bool result = aes128_decrypt.calculate();
        if (!result)
            fail();
        DataBuffer buffer2 = aes128_decrypt.get_data();
        if (buffer2.get_size() != cnt+1)
            fail();
        unsigned char *data_ptr2 = (unsigned char *) buffer2.get_data();
        if (memcmp(data_ptr2, test_data, cnt+1))
            fail();
    }

}
开发者ID:ARMCoderCHS,项目名称:ClanLib,代码行数:55,代码来源:test_aes128.cpp

示例3:

void TestApp::test_aes192()
{
    Console::write_line(" Header: aes192_encrypt.h and aes192_decrypt.h");
    Console::write_line("  Class: AES192_Encrypt and AES192_Decrypt");

    // Test data from http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
    // and http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CBC.pdf

    test_aes192_helper(
        "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b",	// KEY
        "000102030405060708090A0B0C0D0E0F",	// IV
        "6bc1bee22e409f96e93d7e117393172a"	// PLAINTEXT
        "ae2d8a571e03ac9c9eb76fac45af8e51"
        "30c81c46a35ce411e5fbc1191a0a52ef"
        "f69f2445df4f9b17ad2b417be66c3710",
        "4f021db243bc633d7178183a9fa071e8"  // CIPHERTEXT
        "b4d9ada9ad7dedf4e5e738763f69145a"
        "571b242012fb7ae07fa9baac3df102e0"
        "08b0e27988598881d920a9e64f5615cd"
        );
        
    const int test_data_length = 192;
    unsigned char test_data[test_data_length];
    std::vector<unsigned char> key;
    std::vector<unsigned char> iv;
    convert_ascii("8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B", key);
    convert_ascii("000102030405060708090A0B0C0D0E0F", iv);

    for (int cnt=0; cnt<test_data_length; cnt++)
    {
        test_data[cnt] = (unsigned char) cnt;

        AES192_Encrypt aes192_encrypt;
        aes192_encrypt.set_iv(&iv[0]);
        aes192_encrypt.set_key(&key[0]);
        aes192_encrypt.add(test_data, cnt+1);
        aes192_encrypt.calculate();

        AES192_Decrypt aes192_decrypt;
        aes192_decrypt.set_iv(&iv[0]);
        aes192_decrypt.set_key(&key[0]);
        DataBuffer buffer = aes192_encrypt.get_data();
        aes192_decrypt.add(buffer.get_data(), buffer.get_size());
        bool result = aes192_decrypt.calculate();
        if (!result)
            fail();
        DataBuffer buffer2 = aes192_decrypt.get_data();
        if (buffer2.get_size() != cnt+1)
            fail();
        unsigned char *data_ptr2 = (unsigned char *) buffer2.get_data();
        if (memcmp(data_ptr2, test_data, cnt+1))
            fail();
    }

}
开发者ID:ArtHome12,项目名称:ClanLib,代码行数:55,代码来源:test_aes192.cpp

示例4: compress

DataBuffer ZLibCompression::compress(const DataBuffer &data, bool raw, int compression_level, CompressionMode mode)
{
    const int window_bits = 15;

    DataBuffer zbuffer(1024*1024);
    IODevice_Memory output;

    int strategy = MZ_DEFAULT_STRATEGY;
    switch (mode)
    {
    case default_strategy: strategy = MZ_DEFAULT_STRATEGY; break;
    case filtered: strategy = MZ_FILTERED; break;
    case huffman_only: strategy = MZ_HUFFMAN_ONLY; break;
    case rle: strategy = MZ_RLE; break;
    case fixed: strategy = MZ_FIXED; break;
    }

    mz_stream zs = { nullptr };
    int result = mz_deflateInit2(&zs, compression_level, MZ_DEFLATED, raw ? -window_bits : window_bits, 8, strategy); // Undocumented: if wbits is negative, zlib skips header check
    if (result != MZ_OK)
        throw Exception("Zlib deflateInit failed");

    try
    {
        zs.next_in = (unsigned char *) data.get_data();
        zs.avail_in = data.get_size();
        while (true)
        {
            zs.next_out = (unsigned char *) zbuffer.get_data();
            zs.avail_out = zbuffer.get_size();

            int result = mz_deflate(&zs, MZ_FINISH);
            if (result == MZ_NEED_DICT) throw Exception("Zlib deflate wants a dictionary!");
            if (result == MZ_DATA_ERROR) throw Exception("Zip data stream is corrupted");
            if (result == MZ_STREAM_ERROR) throw Exception("Zip stream structure was inconsistent!");
            if (result == MZ_MEM_ERROR) throw Exception("Zlib did not have enough memory to compress file!");
            if (result == MZ_BUF_ERROR) throw Exception("Not enough data in buffer when Z_FINISH was used");
            if (result != MZ_OK && result != MZ_STREAM_END) throw Exception("Zlib deflate failed while compressing zip file!");
            int zsize = zbuffer.get_size() - zs.avail_out;
            if (zsize == 0)
                break;
            output.write(zbuffer.get_data(), zsize);
            if (result == MZ_STREAM_END)
                break;
        }
        mz_deflateEnd(&zs);
    }
    catch (...)
    {
        mz_deflateEnd(&zs);
        throw;
    }

    return output.get_data();
}
开发者ID:eoma,项目名称:gm-engine,代码行数:55,代码来源:zlib_compression.cpp

示例5: load

YETI_Result File::load(const char * path, String & data, FileInterface::open_mode mode /* = YETI_FILE_OPEN_MODE_READ */)
{
    DataBuffer buffer;

    data = "";

    File file(path);
    YETI_Result result = file.open(mode);
    if (YETI_FAILED(result)) return result;

    result = file.load(buffer);

    if (YETI_SUCCEEDED(result) && buffer.get_data_size() > 0) {
        data.assign((const char *)buffer.get_data(), buffer.get_data_size());
        data.set_length(buffer.get_data_size());
    }

    file.close();

    return result;
}
开发者ID:xindawndev,项目名称:cxl-yeti,代码行数:21,代码来源:YetiFile.cpp

示例6: decompress

DataBuffer ZLibCompression::decompress(const DataBuffer &data, bool raw)
{
    const int window_bits = 15;

    DataBuffer zbuffer(1024*1024);
    IODevice_Memory output;

    mz_stream zs = { nullptr };
    int result = mz_inflateInit2(&zs, raw ? -window_bits : window_bits);
    if (result != MZ_OK)
        throw Exception("Zlib inflateInit failed");


    zs.next_in = (unsigned char *) data.get_data();
    zs.avail_in = data.get_size();

    // Continue feeding zlib data until we get our data:
    while (true)
    {
        zs.next_out = (unsigned char *) zbuffer.get_data();
        zs.avail_out = zbuffer.get_size();

        // Decompress data:
        int result = mz_inflate(&zs, 0);
        if (result == MZ_NEED_DICT) throw Exception("Zlib inflate wants a dictionary!");
        if (result == MZ_DATA_ERROR) throw Exception("Zip data stream is corrupted");
        if (result == MZ_STREAM_ERROR) throw Exception("Zip stream structure was inconsistent!");
        if (result == MZ_MEM_ERROR) throw Exception("Zlib did not have enough memory to decompress file!");
        if (result == MZ_BUF_ERROR) throw Exception("Not enough data in buffer when Z_FINISH was used");
        if (result != MZ_OK && result != MZ_STREAM_END) throw Exception("Zlib inflate failed while decompressing zip file!");

        output.write(zbuffer.get_data(), zbuffer.get_size() - zs.avail_out);

        if (result == MZ_STREAM_END)
            break;
    }
    mz_inflateEnd(&zs);

    return output.get_data();
}
开发者ID:eoma,项目名称:gm-engine,代码行数:40,代码来源:zlib_compression.cpp

示例7: decrypt

    Secret RSA::decrypt(const Secret &in_private_exponent, const DataBuffer &in_modulus, const DataBuffer &in_data)
    {
        return RSA_Impl::decrypt(in_private_exponent, in_modulus.get_data(), in_modulus.get_size(), in_data.get_data(), in_data.get_size());
    }
开发者ID:ArtHome12,项目名称:ClanLib,代码行数:4,代码来源:rsa.cpp

示例8:

void SHA384::add(const DataBuffer &data)
{
    add(data.get_data(), data.get_size());
}
开发者ID:finalJ2,项目名称:ClanLib,代码行数:4,代码来源:sha384.cpp

示例9:

    void HashFunctions::md5(const DataBuffer &data, unsigned char out_hash[16])
    {
        md5(data.get_data(), data.get_size(), out_hash);
    }
开发者ID:ArtHome12,项目名称:ClanLib,代码行数:4,代码来源:hash_functions.cpp

示例10: encrypt

    DataBuffer RSA::encrypt(int block_type, Random &random, const DataBuffer &in_public_exponent, const DataBuffer &in_modulus, const Secret &in_data)
    {
        return RSA_Impl::encrypt(block_type, random, in_public_exponent.get_data(), in_public_exponent.get_size(), in_modulus.get_data(), in_modulus.get_size(), in_data.get_data(), in_data.get_size());
    }
开发者ID:ArtHome12,项目名称:ClanLib,代码行数:4,代码来源:rsa.cpp

示例11: set_value_binary

void RegistryKey::set_value_binary(const std::string &name, const DataBuffer &value)
{
    LONG result = RegSetValueEx(impl->key, name.empty() ? 0 : StringHelp::utf8_to_ucs2(name).c_str(), 0, REG_BINARY, (const BYTE *) value.get_data(), value.get_size());
    if (result != ERROR_SUCCESS)
        throw Exception(string_format("Unable to set registry key value %1", name));
}
开发者ID:Cassie90,项目名称:ClanLib,代码行数:6,代码来源:registry_key.cpp

示例12: save

YETI_Result File::save(const DataBuffer & buffer)
{
    OutputStreamReference output;
    YETI_CHECK_WARNING(get_output_stream(output));
    return output->write_fully(buffer.get_data(), buffer.get_data_size());
}
开发者ID:xindawndev,项目名称:cxl-yeti,代码行数:6,代码来源:YetiFile.cpp

示例13:

void SHA512_256::add(const DataBuffer &data)
{
    add(data.get_data(), data.get_size());
}
开发者ID:ARMCoderCHS,项目名称:ClanLib,代码行数:4,代码来源:sha512_256.cpp

示例14: write_bytes

    void File::write_bytes(const std::string &filename, const DataBuffer &bytes)
    {
        File file(filename, create_always, access_write);
        file.write(bytes.get_data(), bytes.get_size());
        file.close();
    }
开发者ID:keigen-shu,项目名称:ClanLib,代码行数:6,代码来源:file.cpp

示例15: add

void AES192_Encrypt::add(const DataBuffer &data)
{
    add(data.get_data(), data.get_size());
}
开发者ID:RobertoMalatesta,项目名称:ClanLib,代码行数:4,代码来源:aes192_encrypt.cpp


注:本文中的DataBuffer::get_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。