2
// Crypt.cpp,v 1.7 2000/04/09 18:24:24 jcej Exp
5
#include "ace/SOCK_Stream.h"
7
/* The expected constructor...
18
/* To send the data we'll apply a signature and encryption.
20
int Crypt::send(ACE_Message_Block *message, ACE_Time_Value *timeout)
22
ACE_UNUSED_ARG(timeout);
24
ACE_DEBUG ((LM_INFO, "(%P|%t) Crypt::send() encrypting (%s)\n", message->rd_ptr() ));
26
// I suspect that some encryptors might change the data size.
27
// It probably isn't safe to create a same-size destination buffer.
28
ACE_Message_Block * encrypted = new ACE_Message_Block(
29
message->size() +16 );
31
// Perform a bogus encryption algorithm and add our safety
32
// signature. Adding the original data size is also probably
33
// a good idea that I haven't encorporated here.
34
ACE_OS::sprintf( encrypted->wr_ptr(), "ED:%s", message->rd_ptr() );
35
encrypted->wr_ptr( strlen(encrypted->wr_ptr())+1 );
37
// Send the encrypted data down the stream to the next module
38
this->put_next( encrypted );
46
/* The upstream movement requires that we decrypt what the peer has
49
int Crypt::recv(ACE_Message_Block *message, ACE_Time_Value *timeout)
51
ACE_UNUSED_ARG(timeout);
53
ACE_DEBUG ((LM_INFO, "(%P|%t) Crypt::recv() decrypting (%s)\n", message->rd_ptr() ));
55
// Create a destination for the decrypted data. The same
56
// block size caveat exists of course.
57
ACE_Message_Block * decrypted = new ACE_Message_Block(
58
message->size() +16 );
60
// Check the signature as expected.
61
if( ACE_OS::strncmp( message->rd_ptr(), "ED:", 3 ) )
63
ACE_DEBUG ((LM_INFO, "(%P|%t) Improperly encrypted data.\n" ));
68
// Don't forget to skip past the signature before decrypting
69
// or things will be quite exciting!
72
// Perform a bogus decryption algorithm
73
ACE_OS::sprintf( decrypted->wr_ptr(), "%s", message->rd_ptr() );
74
decrypted->wr_ptr( strlen(decrypted->wr_ptr())+1 );
76
// Send the decrypted data down the stream to the next module
77
this->put_next( decrypted );