//========================================================================== buffer( buffer const& src ) : parent_data(src.allocator()) { parent_data::allocate(src.size()); #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && BOOST_WORKAROUND(BOOST_MSVC, < 1600) stdext::unchecked_copy(src.begin(),src.end(),begin()); #elif BOOST_WORKAROUND(BOOST_MSVC, > 1500) std::copy(src.begin(),src.end(),stdext::make_unchecked_array_iterator(begin())); #else std::copy(src.begin(),src.end(),begin()); #endif }
friend void copy_limbs(imp * p, buffer<name::imp *> & limbs) { limbs.clear(); while (p != nullptr) { limbs.push_back(p); p = p->m_prefix; } std::reverse(limbs.begin(), limbs.end()); }
buffer(buffer const& b) : m_begin(0) , m_size(0) , m_capacity(0) { if (b.size() == 0) return; resize(b.size()); std::memcpy(m_begin, b.begin(), b.size()); }
buffer(buffer const& b) : m_begin(0) , m_end(0) , m_last(0) { if (b.size() == 0) return; resize(b.size()); std::memcpy(m_begin, b.begin(), b.size()); }
buffer(buffer const & rhs) : std::vector<R>(rhs) , cur(this->begin() + (rhs.cur - rhs.begin())) , fill_helper(rhs.fill_helper) , clone(rhs.clone) { if (rhs.engine) clone(*this, rhs); }
static name mk_fresh_name(environment const & env, buffer<name> const & names, name const & s) { unsigned i = 1; name c = s; while (true) { if (!env.find(c) && std::find(names.begin(), names.end(), c) == names.end()) return c; c = s.append_after(i); i++; } }
std::string comma_list(const buffer& buf) { std::string str; if (buf.size() == 0) str = ""; else if (buf.size() == 1) str = buf.front(); else if (buf.size() == 2) str = buf.front() + " and " + buf.back(); else { buffer::const_iterator it = buf.begin(); str = "and " + *(it++); for (;it != buf.end(); it++) str = *it + ", " + str; } return str; }
/* Collect (and sort) dependencies of collected parameters */ void collect_and_normalize_dependencies(buffer<expr> & norm_params) { name_map<expr> new_types; for (unsigned i = 0; i < m_params.size(); i++) { expr x = m_params[i]; expr new_type = collect(m_ctx.instantiate_mvars(m_ctx.infer(x))); new_types.insert(mlocal_name(x), new_type); } local_context const & lctx = m_ctx.lctx(); std::sort(m_params.begin(), m_params.end(), [&](expr const & l1, expr const & l2) { return lctx.get_local_decl(l1)->get_idx() < lctx.get_local_decl(l2)->get_idx(); }); for (unsigned i = 0; i < m_params.size(); i++) { expr x = m_params[i]; expr type = *new_types.find(mlocal_name(x)); expr new_type = replace_locals(type, i, m_params.data(), norm_params.data()); expr new_param = m_ctx.push_local(local_pp_name(x), new_type, local_info(x)); norm_params.push_back(new_param); } }
expr replace_locals(expr const & e, buffer<expr> const & locals, buffer<expr> const & terms) { lean_assert(locals.size() == terms.size()); lean_assert(std::all_of(locals.begin(), locals.end(), is_local)); return replace_locals(e, locals.size(), locals.data(), terms.data()); }
static bool is_id_first(buffer<char> const & cs, unsigned i) { if (std::isalpha(cs[i]) || cs[i] == '_') return true; unsigned u = utf8_to_unicode(cs.begin() + i, cs.end()); return is_letter_like_unicode(u); }
//Decrypt Buffer in Place void cpl::crypt::blowfish::decrypt(buffer &buf, int iMode) { int n = buf.size(); // n MUST be a power of 8. If not, then we are going to get very strange results. int rem = 8-(n%8); if (rem != 8) { buf.insert(buf.end(), rem, '\0'); n += rem; } assert( n % 8 == 0 ) ; if (n == 0) return; // Nothing to do... block work; buffer bytes(8); block crypt, chain(m_oChain); switch (iMode) { case CBC: //CBC mode, using the Chain for(; n >= 8; n -= 8) { copy(buf.begin()+n-8, buf.begin()+n, bytes.begin()); work = bytesToBlock(bytes); crypt = work; decrypt(work); work ^= chain; chain = crypt; bytes = blockToBytes(work); copy(bytes.begin(), bytes.end(), buf.begin()+n-8); } break; case CFB: //CFB mode, using the Chain, not using Decrypt() for(; n >= 8; n -= 8) { copy(buf.begin()+n-8, buf.begin()+n, bytes.begin()); work = bytesToBlock(bytes); encrypt(chain); crypt = work; work ^= chain; chain = crypt; bytes = blockToBytes(work); copy(bytes.begin(), bytes.end(), buf.begin()+n-8); } break; case ECB: //ECB mode, not using the Chain default: for(; n >= 8; n -= 8) { copy(buf.begin()+n-8, buf.begin()+n, bytes.begin()); work = bytesToBlock(bytes); decrypt(work); bytes = blockToBytes(work); copy(bytes.begin(), bytes.end(), buf.begin()+n-8); } break; } // get the size out of the first 8 chars in the buffer, and then resize it. buffer sizeBuf(8); copy(buf.begin(), buf.begin()+8, sizeBuf.begin()); buf.erase(buf.begin(), buf.begin()+8); int size = decodeInt(sizeBuf); // remove the padding from the end of the file buf.erase(buf.end() - (buf.size() - size), buf.end()); }
//Encrypt Buffer in Place void cpl::crypt::blowfish::encrypt(buffer &buf, int iMode) { int n = buf.size(); // encode & prepend the buffer size buffer sizeBuf = encodeInt(n); buf.insert(buf.begin(), sizeBuf.begin(), sizeBuf.end()); n+=8; // make sure the size of the whole buffer is a factor of 8 by padding it with '\0' characters int rem = 8-(n%8); if (rem != 8) { buf.insert(buf.end(), rem, '\0'); n += rem; } if (n == 0) return; // Nothing to do... block work; buffer bytes(8); block chain(m_oChain); switch (iMode) { case CBC: //CBC mode, using the Chain for(; n >= 8; n -= 8) { copy(buf.begin()+n-8, buf.begin()+n, bytes.begin()); work = bytesToBlock(bytes); work ^= chain; encrypt(work); chain = work; bytes = blockToBytes(work); copy(bytes.begin(), bytes.end(), buf.begin()+n-8); } break; case CFB: //CFB mode, using the Chain for(; n >= 8; n -= 8) { encrypt(chain); copy(buf.begin()+n-8, buf.begin()+n, bytes.begin()); work = bytesToBlock(bytes); work ^= chain; chain = work; bytes = blockToBytes(work); copy(bytes.begin(), bytes.end(), buf.begin()+n-8); } break; case ECB: //ECB mode, not using the Chain default: for(; n >= 8; n -= 8) { std::copy(buf.begin()+n-8, buf.begin()+n, bytes.begin()); work = bytesToBlock(bytes); encrypt(work); bytes = blockToBytes(work); copy(bytes.begin(), bytes.end(), buf.begin()+n-8); } break; } }
constraints mk_constraints(constraint const & c, buffer<constraint> const & cs) { return cons(c, to_list(cs.begin(), cs.end())); }