Boost logo

Boost Users :

Subject: [Boost-users] [asio] AES encryption/decryption
From: Igor R (boost.lists_at_[hidden])
Date: 2009-08-02 14:59:02


Hello all,

Does someone have an experience with the subj?
In my application I need an AES-encrypted socket. I try to accomplish
this by building a custom asio socket that performs all the needed
encryption (with openssl) and delegates the i/o to its service.
However, I encountered an issue that seems to be unsolvable with the
current approach: from one hand, every read opeartion has to return
the number of *decrypted* bytes, but from the other hand,
bytes_readable command returns the size of the available *encrypted*
data. Sometimes this causes severe problems:

void connection::read()
{
  asio::socket_base::bytes_readable command(true);
  socket_.lowest_layer().io_control(command);
  size_t canRead = command.get();
  if (canRead)
    // this line creates completion condition that might never be met,
because read_some() would return less than canRead
    asio::read(socket_, input_, asio::transfer_at_least(canRead), err);
}

I'd appreciate any idea - probably I'm going the wrong way, and
there's some more appropriate design that would give better results?

Thanks.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net