Esempio n. 1
0
int luaopen_ltn12ce_core(lua_State *L) {
    lua_createtable(L, 0, 0);

    // encryption/hashing
    
#ifdef BUILD_CRYPTO
    init_crypto(L);
    init_digest(L);
#endif

    // compression

#ifdef BUILD_BZIP2
    init_comp_bzip2(L);
#endif

#ifdef BUILD_LZMA
    init_comp_lzma(L);
#endif

#ifdef BUILD_ZLIB
    init_comp_zlib(L);
#endif

    return 1;
}
Esempio n. 2
0
/* Calculates the digest of a file, if needed.
 */
static int get_file_digest(File* file)
{
    FILE* stream;
    size_t size;
    char buffer[BUFFER_SIZE];

    if (file->status == HASHED)
        return 0;

    init_digest();

    if (file->status == SAMPLED && file->size <= SAMPLE_SIZE)
        update_digest(file->sample, file->size);
    else if (file->size > 0)
    {
        stream = fopen(file->path, "rb");
        if (!stream)
        {
            if (!quiet_flag)
                warning("%s: %s", file->path, strerror(errno));

            file->status = INVALID;
            return -1;
        }

        for (;;)
        {
            size = fread(buffer, 1, sizeof(buffer), stream);
            if (ferror(stream))
            {
                if (!quiet_flag)
                    warning("%s: %s", file->path, strerror(errno));

                fclose(stream);

                file->status = INVALID;
                return -1;
            }

            if (size == 0)
                break;

            update_digest(buffer, size);
        }

        fclose(stream);
    }

    file->digest = malloc(get_digest_size());
    finish_digest(file->digest);
    file->status = HASHED;
    return 0;
}