Hi,
I'm trying to figure out how Crypto++'s socket system works, and I'm
having trouble grasping the source/sink/filter/transform model and
whether what I'm asking for is even possible. Basically, I want to
build the client and server of a network protocol that communicate by
sending back and forth ASN.1-encoded objects. Since ASN.1 objects all
know their own size, there should be no need for a header or special
framing; just sending the concatenated objects should be sufficient.
The problem is that communication will be bidirectional and there will
be causality between messages: a message from server to client, once
received, will prompt the client to respond with another message, for
instance. I tried the following code:
int main() {
CryptoPP::Socket listen_sock;
listen_sock.Create();
listen_sock.Bind(1234);
listen_sock.Listen();
CryptoPP::Socket talk_sock;
std::cout << "Listening.\n";
bool bl = listen_sock.Accept(talk_sock);
std::cout << "Accept returns " << bl << '\n';
CryptoPP::SocketSource source(talk_sock.GetSocket());
std::cout << "Create BERSequenceDecoder.\n";
CryptoPP::BERSequenceDecoder sequence_decoder(source);
return 0;
}
but once I connect a client to this server, it immediately fails with
BERDecodeError in the constructor without waiting for any data. On the
other hand, if I add a call to PumpAll, the socket blocks until EOF
before continuing (though it does the terminate successfully, assuming
I pipe a DER-encoded ASN.1 message into the other end of the
connection). If I use Pump with a byte count, then I somehow magically
need to know how many bytes to pump in order to get the whole message,
something that the ASN.1 decoding layer ought to be handling for me.
I can't seem to figure out how to do this. What I want is for the
socket to block every time the ASN.1 decoding subsystem calls Get() on
the socket, but to only block for as much data as was requested and to
not block at other times. Is this even possible with the Crypto++
source/sink/filter/transform model? I notice something similar happens
with FileSource objects: if you don't PumpAll() (either explicitly or
using the constructor parameter), you can't use a BERSequenceDecoder
on them because Get() doesn't actually pull bytes from the file.
Thanks,
Chris
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.