本文整理汇总了C++中OTPayload::SetEnvelope方法的典型用法代码示例。如果您正苦于以下问题:C++ OTPayload::SetEnvelope方法的具体用法?C++ OTPayload::SetEnvelope怎么用?C++ OTPayload::SetEnvelope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OTPayload
的用法示例。
在下文中一共展示了OTPayload::SetEnvelope方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessReply
// Process my reply back out to the client. @something.
// For TCP / SSL mode.
void OTClientConnection::ProcessReply(OTMessage &theReply)
{
OT_ASSERT(NULL != m_pPublicKey);
int err = 0;
uint32_t nwritten = 0;
bool bSendCommand = false;
bool bSendPayload = false;
u_header theCMD;
OTPayload thePayload;
memset((void *)theCMD.buf, 0, OT_CMD_HEADER_SIZE); // todo cast
// For now let's send ALL replies in Envelopes (encrypted to public key of client)
// IF we have a public key, that is. Otherwise we send as a normal message.
//
// All messages already require either a public key, or a nymID used to look up a
// public key. So given that I have that information when I reply, I might as well
// ENCRYPT my reply to that same public key. More secure that way.
//
// The wallet (and server) are both ready to open and process these encrypted envelopes.
// If GetKey() returns something, that means the key was set in there, it's
// not just a null pointer. This means we can use it! So let's encrypt to it.
if (m_pPublicKey->IsPublic())
{
OTString strEnvelopeContents(theReply);
// Save the ready-to-go message into a string.
OTEnvelope theEnvelope;
// Seal the string up into an encrypted Envelope
theEnvelope.Seal(*m_pPublicKey, strEnvelopeContents);
// From here on out, theMessage is disposable. OTPayload takes over.
// OTMessage doesn't care about checksums and headers.
thePayload.SetEnvelope(theEnvelope);
// Now that the payload is ready, we'll set up the header.
SetupHeader(&theCMD, CMD_TYPE_1, TYPE_1_CMD_2, thePayload);
}
else
{
thePayload.SetMessage(theReply);
// Now that the payload is ready, we'll set up the header.
SetupHeader(&theCMD, CMD_TYPE_1, TYPE_1_CMD_1, thePayload);
}
bSendCommand = true;
bSendPayload = true;
OTLog::vOutput(2, "\n****************************************************************\n"
"===> Finished setting up header for response.\nFirst 9 bytes are: %d %d %d %d %d %d %d %d %d...\n",
theCMD.buf[0], theCMD.buf[1], theCMD.buf[2], theCMD.buf[3], theCMD.buf[4],
theCMD.buf[5], theCMD.buf[6], theCMD.buf[7], theCMD.buf[8]);
// ------------------------------------------------------------------------------
/*
// Write to Client
strcpy(buffer, "Hello Client!");
SFSocketWrite(clientSocket, buffer, strlen(buffer));
*/
if (bSendCommand)
{
const unsigned int nHeaderSize = OT_CMD_HEADER_SIZE;
for (nwritten = 0; nwritten < nHeaderSize; nwritten += err)
{
// err = SFSocketWrite(m_pSocket, theCMD.buf + nwritten, nHeaderSize - nwritten);
#ifdef _WIN32
if (0 == err || SOCKET_ERROR == err) // 0 means disconnect. error means error. >0 means bytes read.
#else
if (err <= 0)
#endif
break;
}
}
// At this point, we have sent the header across the pipe.
if (bSendPayload)
{
uint32_t nPayloadSize = thePayload.GetSize();
for (nwritten = 0; nwritten < nPayloadSize; nwritten += err)
{
// err = SFSocketWrite(m_pSocket, (unsigned char *)thePayload.GetPayloadPointer() + nwritten, nPayloadSize - nwritten);
#ifdef _WIN32
if (0 == err || SOCKET_ERROR == err) // 0 means disconnect. error means error. >0 means bytes read.
//.........这里部分代码省略.........