/* * State of reading a block and trying to generate its sum. */ static rs_result rs_sig_s_generate(rs_job_t *job) { rs_result result; size_t len; void *block; /* must get a whole block, otherwise try again */ len = job->block_len; result = rs_scoop_read(job, len, &block); /* unless we're near eof, in which case we'll accept * whatever's in there */ if ((result == RS_BLOCKED && rs_job_input_is_ending(job))) { result = rs_scoop_read_rest(job, &len, &block); } else if (result == RS_INPUT_ENDED) { return RS_DONE; } else if (result != RS_DONE) { rs_trace("generate stopped: %s", rs_strerror(result)); return result; } rs_trace("got %ld byte block", (long) len); return rs_sig_do_block(job, block, len); }
/** Read whatever data remains in the input stream. * * \param *job The rs_job_t instance the job instance. * * \param *len will be updated to the length of the available data. * * \param **ptr will point at the available data. * * \return RS_DONE if there was data, RS_INPUT_ENDED if there was no data and * at EOF, RS_BLOCKED if there was no data and not at EOF. */ rs_result rs_scoop_read_rest(rs_job_t *job, size_t *len, void **ptr) { rs_buffers_t *stream = job->stream; *len = job->scoop_avail + stream->avail_in; if (*len) return rs_scoop_read(job, *len, ptr); else if (stream->eof_in) return RS_INPUT_ENDED; else return RS_BLOCKED; }
static rs_result rs_loadsig_s_strong(rs_job_t *job) { rs_result result; rs_strong_sum_t *strongsum; result = rs_scoop_read(job, job->signature->strong_sum_len, (void **) &strongsum); if (result != RS_DONE) return result; job->statefn = rs_loadsig_s_weak; return rs_loadsig_add_sum(job, strongsum); }