summaryrefslogtreecommitdiff
path: root/docs/tutorials/015/Crypt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'docs/tutorials/015/Crypt.cpp')
-rw-r--r--docs/tutorials/015/Crypt.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/docs/tutorials/015/Crypt.cpp b/docs/tutorials/015/Crypt.cpp
index 26827ce44b0..1e20b8f5b42 100644
--- a/docs/tutorials/015/Crypt.cpp
+++ b/docs/tutorials/015/Crypt.cpp
@@ -4,6 +4,8 @@
#include "Crypt.h"
#include "ace/SOCK_Stream.h"
+/* The expected constructor...
+ */
Crypt::Crypt( int _thr_count )
: inherited(_thr_count)
{
@@ -13,13 +15,19 @@ Crypt::~Crypt(void)
{
}
+/* To send the data we'll apply a signature and encryption.
+ */
int Crypt::send(ACE_Message_Block *message, ACE_Time_Value *timeout)
{
ACE_DEBUG ((LM_INFO, "(%P|%t) Crypt::send() encrypting (%s)\n", message->rd_ptr() ));
+ // I suspect that some encryptors might change the data size.
+ // It probably isn't safe to create a same-size destination buffer.
ACE_Message_Block * encrypted = new ACE_Message_Block( message->size() );
- // Perform a bogus encryption algorithm
+ // Perform a bogus encryption algorithm and add our safety
+ // signature. Adding the original data size is also probably
+ // a good idea that I haven't encorporated here.
ACE_OS::sprintf( encrypted->wr_ptr(), "ED:%s", message->rd_ptr() );
encrypted->wr_ptr( strlen(encrypted->wr_ptr())+1 );
@@ -32,12 +40,18 @@ int Crypt::send(ACE_Message_Block *message, ACE_Time_Value *timeout)
return( 0 );
}
+/* The upstream movement requires that we decrypt what the peer has
+ given us.
+*/
int Crypt::recv(ACE_Message_Block *message, ACE_Time_Value *timeout)
{
ACE_DEBUG ((LM_INFO, "(%P|%t) Crypt::recv() decrypting (%s)\n", message->rd_ptr() ));
+ // Create a destination for the decrypted data. The same
+ // block size caveat exists of course.
ACE_Message_Block * decrypted = new ACE_Message_Block( message->size() );
+ // Check the signature as expected.
if( ACE_OS::strncmp( message->rd_ptr(), "ED:", 3 ) )
{
ACE_DEBUG ((LM_INFO, "(%P|%t) Improperly encrypted data.\n" ));
@@ -45,6 +59,8 @@ int Crypt::recv(ACE_Message_Block *message, ACE_Time_Value *timeout)
return(-1);
}
+ // Don't forget to skip past the signature before decrypting
+ // or things will be quite exciting!
message->rd_ptr( 3 );
// Perform a bogus decryption algorithm