// prepare chunk for uploading: mac and encrypt bool HttpReqUL::prepare(FileAccess* fa, const char* tempurl, SymmCipher* key, chunkmac_map* macs, uint64_t ctriv, m_off_t pos, m_off_t npos) { size = (unsigned)(npos - pos); if (!fa->fread(out, size, (-(int)size) & (SymmCipher::BLOCKSIZE - 1), pos)) { return false; } byte mac[SymmCipher::BLOCKSIZE] = { 0 }; char buf[256]; snprintf(buf, sizeof buf, "%s/%" PRIu64, tempurl, pos); setreq(buf, REQ_BINARY); key->ctr_crypt((byte*)out->data(), size, pos, ctriv, mac, 1); memcpy((*macs)[pos].mac, mac, sizeof mac); // unpad for POSTing out->resize(size); return true; }
// prepare file chunk download bool HttpReqDL::prepare(FileAccess* fa, const char* tempurl, SymmCipher* key, chunkmac_map* macs, uint64_t ctriv, m_off_t pos, m_off_t npos) { char urlbuf[256]; snprintf(urlbuf, sizeof urlbuf, "%s/%" PRIu64 "-%" PRIu64, tempurl, pos, npos - 1); setreq(urlbuf, REQ_BINARY); dlpos = pos; size = (unsigned)(npos - pos); if (!buf || buflen != size) { // (re)allocate buffer if (buf) { delete[] buf; } buf = new byte[(size + SymmCipher::BLOCKSIZE - 1) & - SymmCipher::BLOCKSIZE]; buflen = size; } return true; }
static void recalc_tty_req(Tty *tty) { setreq(tty->bus, TTY, tty->tto_flag || tty->tti_flag ? tty->pia : 0); }