Exemple #1
0
void IDEA::setkey(const std::string & KEY){
    if (keyset){
        throw std::runtime_error("Error: Key has already been set.");
    }
    if (KEY.size() != 16){
        throw std::runtime_error("Error: Key must be 128 bits in length.");
    }

    std::string key = hexlify(KEY);
    std::vector <std::string> temp;
    for(uint8_t x = 0; x < 7; x++){

        for(int y  = 0; y < 8; y++){
            temp.push_back(key.substr(y << 2, 4));
        }

        for(uint8_t y = 0; y < 16; y++){
            key += makebin(toint(key.substr(y << 1 , 2), 16), 8);
        }

        key = key.substr(32, 128);
        key = key.substr(25, 103) + key.substr(0, 25);

        for(uint8_t y = 0; y < 16; y++){
            key += makehex(toint(key.substr(y << 3, 8), 2), 2);
        }

        key = key.substr(128, 32);
    }

    temp.erase(temp.begin() + 52, temp.end());

    for(uint8_t x = 0; x < temp.size(); x++){
        k.push_back(toint(temp[x], 16));
    }
    keyset = true;
}
Exemple #2
0
bool kernel::recv_message(channel_handle, const message::inv& message)
{
    message::inv request_invs;
    for (const message::inv_vect curr_inv: message.invs)
    {
        if (curr_inv.type == message::inv_type::none)
            return false;

        if (curr_inv.type == message::inv_type::error)
            log_debug() << "ERROR";
        else if (curr_inv.type == message::inv_type::transaction)
            log_debug() << "MSG_TX";
        else if (curr_inv.type == message::inv_type::block)
            log_debug() << "MSG_BLOCK";
        log_debug() << hexlify(curr_inv.hash);

        // Push only block invs to the request queue
        if (curr_inv.type == message::inv_type::block)
            request_invs.invs.push_back(curr_inv);
    }
    storage_component_->store(request_invs, null);
    accept_inventories(std::error_code(), request_invs.invs);
    return true;
}
Exemple #3
0
std::string input::toString() const
{
    return hexlify(_data, _size);
}
Exemple #4
0
bool kernel::recv_message(channel_handle, const message::addr& message)
{
    for (const message::net_addr addr: message.addr_list)
        log_debug() << hexlify(addr.ip_addr) << ' ' << addr.port;
    return true;
}
Exemple #5
0
Values sign(const std::string & data, const Values & pri, const Values & pub, MPI k){
    MPI m(hexlify(data), 16);
    return sign(rawtompi(data), pri, pub, k);
}
Exemple #6
0
void Tag18::show_contents(HumanReadable & hr) const {
    hr << "Version: " + std::to_string(version)
       << "Encrypted Data (" + std::to_string(protected_data.size()) + " octets): " + hexlify(protected_data);
}
Exemple #7
0
TEST(test_encoder, test_encode_string) {
  uint8_t data[4];
  pb_ostream_t stream = pb_ostream_from_buffer(data, sizeof(data));
  ASSERT_EQ(KRPC_OK, krpc_encode_string(&stream, "foo"));
  ASSERT_EQ("03666f6f", hexlify(data, stream.bytes_written));
}
Exemple #8
0
TEST(test_encoder, test_encode_value) {
  uint8_t data[2];
  pb_ostream_t stream = pb_ostream_from_buffer(data, sizeof(data));
  ASSERT_EQ(KRPC_OK, krpc_encode_uint32(&stream, 300));
  ASSERT_EQ("ac02", hexlify(data, stream.bytes_written));
}
static convert_to_flat_code_t convert_to_flat_iterator(
    to_flat_state_t *state,
    const node_t *node) {
  assert(node->type == TYPE_IMPLICIT || node->type == TYPE_ROOT);

  for (uint32_t ix = 0; ix < node->num_children; ix++) {
    node_t *child = get_child_by_index(node, ix);

    if (child->type == TYPE_LEAF) {
      size_t space_needed = state->dirpath_build_buffer_idx +
                            child->name_sz +
                            1 /* null character */ +
                            (SHA1_BYTES * 2) +
                            (child->flags != '\000' ? 1 : 0) +
                            1 /* NL */;

      if (CONVERT_EXPAND_TO_FIT(
              &state->output_buffer,
              state->output_buffer_idx,
              &state->output_buffer_sz,
              space_needed) == false) {
        return CONVERT_TO_FLAT_OOM;
      }

      // copy the dirpath over to the output buffer.
      memcpy(&state->output_buffer[state->output_buffer_idx],
          state->dirpath_build_buffer,
          state->dirpath_build_buffer_idx);
      state->output_buffer_idx += state->dirpath_build_buffer_idx;

      // copy the filename over to the output buffer.
      memcpy(&state->output_buffer[state->output_buffer_idx],
          child->name, child->name_sz);
      state->output_buffer_idx += child->name_sz;

      // copy the filename over to the output buffer.
      state->output_buffer[state->output_buffer_idx] = '\000';
      state->output_buffer_idx++;

      // transcribe the sha over.
      hexlify(child->checksum, SHA1_BYTES,
          &state->output_buffer[state->output_buffer_idx]);
      state->output_buffer_idx += (SHA1_BYTES * 2);

      if (child->flags != '\000') {
        state->output_buffer[state->output_buffer_idx] = child->flags;
        state->output_buffer_idx++;
      }

      state->output_buffer[state->output_buffer_idx] = '\n';
      state->output_buffer_idx++;

      assert(state->output_buffer_idx < state->output_buffer_sz);
    } else {
      // save the old value...
      size_t previous_dirpath_build_buffer_idx =
          state->dirpath_build_buffer_idx;

      if (PATH_APPEND(
              &state->dirpath_build_buffer,
              &state->dirpath_build_buffer_idx,
              &state->dirpath_build_buffer_sz,
              child->name,
              child->name_sz) == false) {
        return CONVERT_TO_FLAT_OOM;
      }

      convert_to_flat_iterator(state, child);

      state->dirpath_build_buffer_idx = previous_dirpath_build_buffer_idx;
    }
  }

  return CONVERT_TO_FLAT_OK;
}
Exemple #10
0
int32_t		mfso::readFromMapping(FileMapping* fm, fdinfo* fi, void* buff, uint32_t size)
{
  VFile*		vfile;
  chunk*		current;
  uint64_t		relativeoffset;
  uint32_t		currentread;
  uint32_t		totalread;
  bool			eof;
  uint32_t		relativesize;
  CacheContainer*	container;
  VFilePool&		vfilePool = VFilePool::instance(); //this->vfilePool ? 

  eof = false;
  totalread = 0;
   
  while ((totalread < size) && (!eof))
  {
      try
      {
	  current = fm->chunkFromOffset(fi->offset);
	  relativeoffset = current->originoffset + (fi->offset - current->offset);
	  if ((size - totalread) < (current->offset + current->size - fi->offset))
	    relativesize = size - totalread;
	  else
	    relativesize = current->offset + current->size - fi->offset;
	  if (current->origin != NULL)
          {
	      if (this->__verbose == true)
              {
		  std::cout << "[" << this->name << "] reading " << fi->node->absolute() << std::endl
			    << "   " << hexlify(fi->offset) << "-" << hexlify(fi->offset + relativesize)
			    << " mapped @ " << hexlify(relativeoffset) << "-" << hexlify(relativeoffset + relativesize)
			    << " in " << current->origin->absolute() << std::endl;
              }

              container = vfilePool.find(current->origin);
              if (container == NULL)
                vfile = current->origin->open();
              else
                vfile = (VFile*)container->content;
              //vfile = current->origin->open();

	      vfile->seek(relativeoffset);
	      if ((currentread = vfile->read(((uint8_t*)buff) + totalread, relativesize)) == 0)
		  eof = true;

              if (container != NULL)
                vfilePool.unused(container);
              else
                vfilePool.insert(vfile);
	      //vfile->close();
	      fi->offset += currentread;
	      totalread += currentread;
	  }
	  else if (current->size != 0)
	  {
	      memset((uint8_t*)buff+totalread, 0, relativesize);
	      if (this->__verbose == true)
              {
		  std::cout << "[" << this->name << "] reading " << fi->node->absolute() << std::endl
			    << "   " << hexlify(fi->offset) << "-" << hexlify(fi->offset + relativesize)
			    << " mapped @ " << hexlify(relativeoffset) << "-" << hexlify(relativeoffset + relativesize)
			    << " in shadow node" << std::endl;
              }
	      fi->offset += relativesize;
	      totalread += relativesize;
	  }
	  else
          {
	    throw("chunk is not valid");
	  }
      }
      catch(...)
      {
	  eof = true;
      }
  }
  return (totalread);
}
Exemple #11
0
void Tag61::show_contents(HumanReadable & hr) const {
    hr << hexlify(stream);
}