Beispiel #1
0
        void save_binary_chunk(void const* address, std::size_t count) // override
        {
            if (filter_ || chunks_ == 0 || count < HPX_ZERO_COPY_SERIALIZATION_THRESHOLD) {
                // fall back to serialization_chunk-less archive
                this->output_container::save_binary(address, count);
            }
            else {
                HPX_ASSERT(get_num_chunks() > current_chunk_);
                HPX_ASSERT(
                    get_chunk_type(current_chunk_) == chunk_type_index ||
                    get_chunk_size(current_chunk_) != 0);

                // complement current serialization_chunk by setting its length
                if (get_chunk_type(current_chunk_) == chunk_type_index)
                {
                    HPX_ASSERT(get_chunk_size(current_chunk_) == 0);

                    set_chunk_size(current_chunk_,
                        current_ - get_chunk_data(current_chunk_).index_);
                }

                // add a new serialization_chunk referring to the external buffer
                chunks_->push_back(create_pointer_chunk(address, count));
                ++current_chunk_;
            }
        }
Beispiel #2
0
        void save_binary(void const* address, std::size_t count) // override
        {
            HPX_ASSERT(count != 0);
            {
                if (filter_) {
                    filter_->save(address, count);
                }
                else {
                    // make sure there is a current serialization_chunk descriptor
                    // available
                    if (chunks_)
                    {
                        HPX_ASSERT(get_num_chunks() > current_chunk_);
                        if (get_chunk_type(current_chunk_) == chunk_type_pointer ||
                            get_chunk_size(current_chunk_) != 0)
                        {
                            // add a new serialization_chunk
                            chunks_->push_back(create_index_chunk(current_, 0));
                            ++current_chunk_;
                        }
                    }

                    if (cont_.size() < current_ + count)
                        cont_.resize(cont_.size() + count);

                    if (count == 1)
                        cont_[current_] = *static_cast<unsigned char const*>(address);
                    else
                        std::memcpy(&cont_[current_], address, count);
                }
                current_ += count;
            }
        }
Beispiel #3
0
        void set_filter(binary_filter* filter) // override
        {
            HPX_ASSERT(0 == filter_);
            filter_ = filter;
            start_compressing_at_ = current_;

            if (chunks_) {
                HPX_ASSERT(get_num_chunks() == 1 && get_chunk_size(0) == 0);
                chunks_->clear();
            }
        }
Beispiel #4
0
static int htc_aes_crypt(FILE *in, FILE *out, char *key, char *iv, 
                  unsigned char chunks_in, htc_aes_progress_t callback,
                  htc_aes_crypt_t crypt_func)
{
    char buf[HTC_AES_READBUF], orig_iv[HTC_AES_KEYSIZE];
    unsigned int pos, size, chunks, bytes, chunksdone = 0;
    unsigned int count = HTC_AES_READBUF_ROUNDS + 1;
    unsigned int chunk_size = (((int)chunks_in)<<HTC_AES_CHUNK_SIZE); 
    MCRYPT td;

    /* Get size of zip data. */
    pos = ftell(in);
    fseek(in, 0, SEEK_END);
    size = ftell(in) - pos;
    fseek(in, pos, SEEK_SET);
    
    chunks = get_num_chunks(size, chunk_size);
    
    td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, NULL, MCRYPT_CBC, NULL);
    
    if(td == MCRYPT_FAILED) {
        perror("failed to open mcrypt module");
        return 0;
    }

    memcpy(orig_iv, iv, HTC_AES_KEYSIZE);

    while((bytes = fread(buf, sizeof(char), sizeof(buf), in)) > 0) {
        if(callback) callback(ftell(in), size);
        if(chunksdone < chunks) {
            if((ftell(in) - bytes - pos) % chunk_size == 0) {
                count = 0;
                memcpy(iv, orig_iv, HTC_AES_KEYSIZE);
            }            
            
            if(count < HTC_AES_READBUF_ROUNDS) {
                crypt_func(td, buf, sizeof(buf), key, iv);
                count++;
            } else if(count == HTC_AES_READBUF_ROUNDS) {
                chunksdone++;
                count++;
            }
        }
        fwrite(buf, sizeof(char), sizeof(buf), out);
    }

    mcrypt_module_close(td);
    return 1;
}
Beispiel #5
0
        void save_binary(void const* address, std::size_t count) // override
        {
            HPX_ASSERT(count != 0);
            {
                if (filter_) {
                    filter_->save(address, count);
                }
                else {
                    // make sure there is a current serialization_chunk descriptor
                    // available
                    if (chunks_)
                    {
                        HPX_ASSERT(get_num_chunks() > current_chunk_);
                        if (get_chunk_type(current_chunk_) == chunk_type_pointer ||
                            get_chunk_size(current_chunk_) != 0)
                        {
                            // add a new serialization_chunk, reuse chunks,
                            // if possible
                            // the chunk size will be set at the end
                            if (chunks_->size() <= current_chunk_ + 1)
                            {
                                chunks_->push_back(
                                    create_index_chunk(current_, 0));
                                ++current_chunk_;
                            }
                            else
                            {
                                (*chunks_)[++current_chunk_] =
                                    create_index_chunk(current_, 0);
                            }
                        }
                    }

                    if (cont_.size() < current_ + count)
                        cont_.resize(cont_.size() + count);

                    detail::access_data<Container>::write(
                        cont_, count, current_, address);
                }
                current_ += count;
            }
        }
Beispiel #6
0
        ~output_container()
        {
            if (filter_) {
                std::size_t written = 0;

                if (cont_.size() < current_)
                    cont_.resize(current_);
                current_ = start_compressing_at_;

                do {
                    bool flushed = filter_->flush(&cont_[current_],
                        cont_.size()-current_, written);

                    current_ += written;
                    if (flushed)
                        break;

                    // resize container
                    cont_.resize(cont_.size()*2);

                } while (true);

                cont_.resize(current_);         // truncate container
            }
            else if (chunks_) {
                HPX_ASSERT(get_num_chunks() > current_chunk_);
                HPX_ASSERT(
                    get_chunk_type(current_chunk_) == chunk_type_index ||
                    get_chunk_size(current_chunk_) != 0);

                // complement current serialization_chunk by setting its length
                if (get_chunk_type(current_chunk_) == chunk_type_index)
                {
                    HPX_ASSERT(get_chunk_size(current_chunk_) == 0);

                    set_chunk_size(current_chunk_,
                        current_ - get_chunk_data(current_chunk_).index_);
                }
            }
        }