Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTPayload Class Reference

#include <OTPayload.hpp>

Inheritance diagram for opentxs::OTPayload:
Collaboration diagram for opentxs::OTPayload:

Public Member Functions

EXPORT OTPayload ()
 
 OTPayload (const void *pNewData, uint32_t nNewSize)
 
 OTPayload (const OTPayload &rhs)
 
 OTPayload (const OTASCIIArmor &theSource)
 
virtual EXPORT ~OTPayload ()
 
EXPORT uint32_t ReadBytesFrom (OTData &theData, uint32_t lSize)
 
EXPORT void SetPayloadSize (uint32_t lNewSize)
 
EXPORT const void * GetPayloadPointer () const
 
EXPORT bool SetMessagePayload (const OTMessage &theMessage)
 
EXPORT bool GetMessagePayload (OTMessage &theMessage) const
 
EXPORT bool GetEnvelope (OTEnvelope &theEnvelope) const
 
EXPORT bool SetEnvelope (const OTEnvelope &theEnvelope)
 
- Public Member Functions inherited from opentxs::OTData
EXPORT OTData ()
 
EXPORT OTData (const void *data, uint32_t size)
 
EXPORT OTData (const OTData &source)
 
EXPORT OTData (const OTASCIIArmor &source)
 
virtual EXPORT ~OTData ()
 
virtual EXPORT void Release ()
 
EXPORT void Release_Data ()
 
void SetSize (uint32_t size)
 
const void * GetPointer () const
 
EXPORT OTDataoperator= (OTData rhs)
 
EXPORT void swap (OTData &rhs)
 
EXPORT bool operator== (const OTData &rhs) const
 
EXPORT bool operator!= (const OTData &rhs) const
 
EXPORT OTDataoperator+= (const OTData &rhs)
 
EXPORT bool IsEmpty () const
 
uint32_t GetSize () const
 
EXPORT void Assign (const OTData &source)
 
EXPORT void Assign (const void *data, uint32_t size)
 
EXPORT void Concatenate (const void *data, uint32_t size)
 
EXPORT bool Randomize (uint32_t size)
 
EXPORT void zeroMemory () const
 
EXPORT uint32_t OTfread (uint8_t *data, uint32_t size)
 
void reset ()
 

Additional Inherited Members

- Protected Member Functions inherited from opentxs::OTData
void Initialize ()
 

Detailed Description

Definition at line 145 of file OTPayload.hpp.

Constructor & Destructor Documentation

opentxs::OTPayload::OTPayload ( )

Definition at line 145 of file OTPayload.cpp.

146  : OTData()
147 {
148 }
EXPORT OTData()
Definition: OTData.cpp:145
opentxs::OTPayload::OTPayload ( const void *  pNewData,
uint32_t  nNewSize 
)

Definition at line 150 of file OTPayload.cpp.

151  : OTData(pNewData, nNewSize)
152 {
153 }
EXPORT OTData()
Definition: OTData.cpp:145
opentxs::OTPayload::OTPayload ( const OTPayload rhs)

Definition at line 155 of file OTPayload.cpp.

156  : OTData(rhs)
157 {
158 }
EXPORT OTData()
Definition: OTData.cpp:145
opentxs::OTPayload::OTPayload ( const OTASCIIArmor theSource)

Definition at line 160 of file OTPayload.cpp.

161  : OTData(theSource)
162 {
163 }
EXPORT OTData()
Definition: OTData.cpp:145
opentxs::OTPayload::~OTPayload ( )
virtual

Definition at line 165 of file OTPayload.cpp.

166 {
167 }

Member Function Documentation

bool opentxs::OTPayload::GetEnvelope ( OTEnvelope theEnvelope) const

Definition at line 232 of file OTPayload.cpp.

233 {
234  // validate checksum
235  uint32_t lSize = GetSize();
236  uint32_t lIndex = lSize - 2; // the index to where the nullptr terminator
237  // SHOULD be if they
238  // sent us a base64-encoded string, containing an encrypted message. (which
239  // we expect...)
240 
241  // (lSize-1 would be the location of the checksum at the end.)
242  if (0 == lSize) return false;
243 
244  if (IsChecksumValid((OT_BYTE*)GetPointer(), (uint32_t)lSize)) {
245  // We add the null-terminator ourselves at this point, for security
246  // reasons,
247  // since we will process the data, soon after this function, as a
248  // string.
249  ((OT_BYTE*)GetPointer())[lIndex] = 0;
250 
251  theEnvelope.m_dataContents.Release();
252 
253  OTASCIIArmor theArmor;
254  // Why is this safe, where I cast the Payload data pointer as
255  // a char * and tell the data object to set itself from that?
256  // Because (1) I just validated the checksum, and
257  // (2) There place where the nullptr should be, I set to 0, by hand,
258  // just above 2 lines. So when this set operation occurs, the
259  // farthest it will go is to that 0.
260  theArmor.Set((const char*)GetPointer());
261 
262  // Todo NOTE: If I ever want to process bookends here instead of
263  // assuming they aren't there,
264  // IT'S VERY EASY!! All I have to do is call theArmor.LoadFromString
265  // instead of theArmor.Set.
266 
267  // Now the ascii-armored string that was sent across is decoded back to
268  // binary into the
269  // Envelope object.
270  theEnvelope.SetAsciiArmoredData(theArmor);
271  return true;
272  }
273  else {
274  otErr << "Invalid Checksum in OTPayload::GetEnvelope\n";
275  return false;
276  }
277 }
EXPORT OT_BOOL IsChecksumValid(OT_BYTE *buffer, uint32_t size)
OTLOG_IMPORT OTLogStream otErr
const void * GetPointer() const
Definition: OTData.hpp:162
friend class OTASCIIArmor
Definition: OTData.hpp:145
uint32_t GetSize() const
Definition: OTData.hpp:174
uint8_t OT_BYTE
bool opentxs::OTPayload::GetMessagePayload ( OTMessage theMessage) const

Definition at line 280 of file OTPayload.cpp.

281 {
282  // validate checksum
283  uint32_t lSize = GetSize();
284  uint32_t lIndex = lSize - 2; // the index to where the nullptr terminator
285  // SHOULD be if they
286  // sent us a string like they were supposed to. (A contract.)
287  // (nSize-1 would be the location of the checksum at the end.)
288  if (0 == lSize) return false;
289 
290  if (IsChecksumValid((OT_BYTE*)GetPointer(), (uint32_t)lSize)) {
291  // We add the null-terminator ourselves at this point, for security
292  // reasons,
293  // since we will process the data, after this point, as a string.
294  ((OT_BYTE*)GetPointer())[lIndex] = 0;
295 
296  theMessage.Release();
297 
298  // Why is this safe, where I cast the Payload data pointer as
299  // a char * and tell the string to set itself from that?
300  // Because (1) I just validated the checksum, and
301  // (2) There place where the nullptr should be, I set to 0, by hand,
302  // just above 2 lines. So when this set operation occurs, the
303  // farthest it will go is to that 0.
304  theMessage.m_strRawFile.Set((const char*)GetPointer());
305  return true;
306  }
307  else {
308  otErr << "Invalid Checksum in OTPayload::GetMessage\n";
309  return false;
310  }
311 }
EXPORT OT_BOOL IsChecksumValid(OT_BYTE *buffer, uint32_t size)
OTLOG_IMPORT OTLogStream otErr
const void * GetPointer() const
Definition: OTData.hpp:162
uint32_t GetSize() const
Definition: OTData.hpp:174
uint8_t OT_BYTE
const void * opentxs::OTPayload::GetPayloadPointer ( ) const

Definition at line 318 of file OTPayload.cpp.

319 {
320  return GetPointer();
321 }
const void * GetPointer() const
Definition: OTData.hpp:162
uint32_t opentxs::OTPayload::ReadBytesFrom ( OTData theData,
uint32_t  lSize 
)

Definition at line 169 of file OTPayload.cpp.

170 {
171  OT_ASSERT(theData.GetSize() >= lSize);
172 
173  // The size requested to read MUST be less or equal to size of theData
174  if (theData.GetSize() < lSize) abort();
175 
176  OTPayload& refPayload = (OTPayload&)theData; // todo fix this cast.
177 
178  // Copy from theData to this, up until lSize
179  Assign(refPayload.GetPayloadPointer(), lSize);
180 
181  // Create a temp var, starting from theData+lSize, copying to the end of
182  // theData
183  OTData TEMPdata((uint8_t*)refPayload.GetPayloadPointer() + lSize,
184  theData.GetSize() - lSize);
185 
186  // theData is assigned to TEMPdata (thus removing from it the bytes that we
187  // just read into this.)
188  theData.Assign(TEMPdata);
189 
190  return lSize;
191 }
EXPORT OTData()
Definition: OTData.cpp:145
EXPORT void Assign(const OTData &source)
Definition: OTData.cpp:275
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTPayload::SetEnvelope ( const OTEnvelope theEnvelope)

Definition at line 194 of file OTPayload.cpp.

195 {
196  OTASCIIArmor theArmor;
197 
198  if (theEnvelope.GetAsciiArmoredData(theArmor)) {
199  uint32_t lSize = theArmor.GetLength() + 1; //+1 for the null terminater
200 
201  if (theArmor.GetLength()) {
202  SetPayloadSize(lSize + 1); // +1 for the checksum byte.
203 
204  // Copy it in.
205  memcpy((void*)GetPointer(), theArmor.Get(), lSize);
206 
207  // Add the checksum, success.
208  AppendChecksum((OT_BYTE*)GetPointer(), lSize);
209  return true;
210  }
211  }
212  return false;
213 }
EXPORT void SetPayloadSize(uint32_t lNewSize)
Definition: OTPayload.cpp:313
const void * GetPointer() const
Definition: OTData.hpp:162
void AppendChecksum(OT_BYTE *buffer, uint32_t &size)
friend class OTASCIIArmor
Definition: OTData.hpp:145
uint8_t OT_BYTE
bool opentxs::OTPayload::SetMessagePayload ( const OTMessage theMessage)

Definition at line 215 of file OTPayload.cpp.

216 {
217  uint32_t lSize =
218  theMessage.m_strRawFile.GetLength() + 1; //+1 for the null terminater
219 
220  if (theMessage.m_strRawFile.GetLength()) {
221  SetPayloadSize(lSize + 1); // +1 for the checksum byte.
222  memcpy((void*)GetPointer(), theMessage.m_strRawFile.Get(), lSize);
223 
224  // Add the checksum
225  AppendChecksum((OT_BYTE*)GetPointer(), lSize);
226  return true;
227  }
228  return false;
229 }
EXPORT void SetPayloadSize(uint32_t lNewSize)
Definition: OTPayload.cpp:313
const void * GetPointer() const
Definition: OTData.hpp:162
void AppendChecksum(OT_BYTE *buffer, uint32_t &size)
uint8_t OT_BYTE
void opentxs::OTPayload::SetPayloadSize ( uint32_t  lNewSize)

Definition at line 313 of file OTPayload.cpp.

314 {
315  SetSize(lNewSize);
316 }
void SetSize(uint32_t size)
Definition: OTData.cpp:386

The documentation for this class was generated from the following files: