~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to docs/tutorials/015/Crypt.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
// Crypt.cpp,v 1.7 2000/04/09 18:24:24 jcej Exp
3
 
 
4
 
#include "Crypt.h"
5
 
#include "ace/SOCK_Stream.h"
6
 
 
7
 
/* The expected constructor...
8
 
 */
9
 
Crypt::Crypt( void )
10
 
        : Protocol_Task()
11
 
{
12
 
}
13
 
 
14
 
Crypt::~Crypt(void)
15
 
{
16
 
}
17
 
 
18
 
/* To send the data we'll apply a signature and encryption.
19
 
 */
20
 
int Crypt::send(ACE_Message_Block *message, ACE_Time_Value *timeout)
21
 
{
22
 
    ACE_UNUSED_ARG(timeout);
23
 
 
24
 
    ACE_DEBUG ((LM_INFO, "(%P|%t) Crypt::send() encrypting (%s)\n", message->rd_ptr() ));
25
 
 
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 );
30
 
 
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 );
36
 
 
37
 
        // Send the encrypted data down the stream to the next module
38
 
    this->put_next( encrypted );
39
 
 
40
 
        // We're done here.
41
 
    message->release();
42
 
 
43
 
    return( 0 );
44
 
}
45
 
 
46
 
/* The upstream movement requires that we decrypt what the peer has
47
 
   given us.
48
 
*/
49
 
int Crypt::recv(ACE_Message_Block *message, ACE_Time_Value *timeout)
50
 
{
51
 
    ACE_UNUSED_ARG(timeout);
52
 
 
53
 
    ACE_DEBUG ((LM_INFO, "(%P|%t) Crypt::recv() decrypting (%s)\n", message->rd_ptr() ));
54
 
 
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 );
59
 
 
60
 
        // Check the signature as expected.
61
 
    if( ACE_OS::strncmp( message->rd_ptr(), "ED:", 3  ) )
62
 
    {
63
 
        ACE_DEBUG ((LM_INFO, "(%P|%t) Improperly encrypted data.\n" ));
64
 
        message->release();
65
 
        return(-1);
66
 
    }
67
 
 
68
 
        // Don't forget to skip past the signature before decrypting
69
 
        // or things will be quite exciting!
70
 
    message->rd_ptr( 3 );
71
 
 
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 );
75
 
 
76
 
        // Send the decrypted data down the stream to the next module
77
 
    this->put_next( decrypted );
78
 
 
79
 
        // We're done here.
80
 
    message->release();
81
 
 
82
 
    return( 0 );
83
 
}