本文整理汇总了C++中OTEnvelope::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ OTEnvelope::Open方法的具体用法?C++ OTEnvelope::Open怎么用?C++ OTEnvelope::Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OTEnvelope
的用法示例。
在下文中一共展示了OTEnvelope::Open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessMessage_ZMQ
void ProcessMessage_ZMQ(const std::string & str_Message, std::string & str_Reply)
{
OT_ASSERT(NULL != g_pServer);
if (str_Message.size() < 1)
return;
// --------------------
// return value.
std::string resultString = ""; // Whatever we put in this string is what will get returned.
// First we grab the client's message
OTASCIIArmor ascMessage;
ascMessage.MemSet(str_Message.data(), str_Message.size());
// ------------------
//
// OTPayload thePayload;
// thePayload.SetPayloadSize(str_Message.size());
// memcpy((void*)thePayload.GetPayloadPointer(), str_Message.data(), str_Message.size());
// ----------------------------------------------------------------------
// OTLog::vError("Envelope: \n%s\n Size: %ld\n", ascMessage.Get(), ascMessage.GetLength());
OTMessage theMsg, theReply; // we'll need these in a sec...
// OTEnvelope theEnvelope(ascMessage); // Now the base64 is decoded and unpacked, and the envelope is in binary form again.
OTEnvelope theEnvelope; // Now the base64 is decoded and the envelope is in binary form again.
if (theEnvelope.SetAsciiArmoredData(ascMessage))
{
OTLog::Output(2, "Successfully retrieved envelope from ZMQ message...\n");
OTString strEnvelopeContents;
// OTString strPubkeyPath("TESTPUBKEY.txt");
// g_pServer->GetServerNym().SavePublicKey(strPubkeyPath);
// Decrypt the Envelope.
if (theEnvelope.Open(g_pServer->GetServerNym(), strEnvelopeContents)) // now strEnvelopeContents contains the decoded message.
{
// All decrypted--now let's load the results into an OTMessage.
// No need to call theMsg.ParseRawFile() after, since
// LoadContractFromString handles it.
//
if (strEnvelopeContents.Exists() && theMsg.LoadContractFromString(strEnvelopeContents))
{
// In case you want to see all the incoming messages...
// OTLog::vOutput(0, "%s\n\n", strEnvelopeContents.Get());
// By constructing this without a socket, I put it in XmlRpc/http mode, instead of tcp/ssl.
OTClientConnection theClient(*g_pServer);
// By optionally passing in &theClient, the client Nym's public key will be
// set on it whenever verification is complete. (So for the reply, I'll
// have the key and thus I'll be able to encrypt reply to the recipient.)
if (g_pServer->ProcessUserCommand(theMsg, theReply, &theClient))
{
// At this point the reply is ready to go, and theClient has the public key of the recipient...
OTLog::vOutput(1, "Successfully processed user command: %s.\n", theMsg.m_strCommand.Get());
// The transaction is now processed, and the server's reply message is in theReply.
// Let's seal it up to the recipient's nym (in an envelope) and send back to the user...
OTEnvelope theRecipientEnvelope;
bool bSealed = theClient.SealMessageForRecipient(theReply, theRecipientEnvelope);
if (bSealed)
{
// OTPayload theReplyPayload;
// theReplyPayload.SetEnvelope(theRecipientEnvelope);
//
// resultString = ascReply.Get();
// resultString.assign(theReplyPayload.GetPayloadPointer(), theReplyPayload.GetPayloadSize());
OTASCIIArmor ascReply;
if (theRecipientEnvelope.GetAsciiArmoredData(ascReply));
resultString.assign(ascReply.Get(), ascReply.GetLength());
}
else
OTLog::Output(0, "Unable to seal envelope in ProcessMessage_ZMQ.\n");
}
else
OTLog::Output(0, "Unable to process user command in ProcessMessage_ZMQ.\n");
}
else
OTLog::Error("Error loading message from envelope contents. ProcessMessage_ZMQ.\n");
}
else
OTLog::Error("Unable to open envelope. ProcessMessage_ZMQ.\n");
}
else
OTLog::Error("Error retrieving envelope from ProcessMessage_ZMQ.\n");
// ----------------------------------------------------------------------
//.........这里部分代码省略.........
示例2: if
//.........这里部分代码省略.........
// Uh-oh, somehow the number of bytes read was less than what we expected...
else if (nread < theCMD.fields.size)
{
// TODO: Verify that the amount read matched the amount expected
// if not, we have a problem that needs to be handled.
// Long term solution is to buffer the data as a comes in and just
// add it to the buffer.
// Then if we don't have the complete message yet, we just come around next
// time some data is read, and we add that to the buffer, THEN we check to see
// if there are enough bytes yet read to match the amount expected according to
// the header.
//
// Until I can do that, I'm not yet TRULY asynchronous. TODO: lookup a good buffer class.
OTLog::Error("Number of bytes read did NOT match size in header.\n");
return false;
}
else
OTLog::vOutput(2, "Loaded a payload, size: %d\n", theCMD.fields.size);
// ------------------------------------------------------------
// Okay so now we've received the expected size from the socket. Let's transfer it
// into an object type that we can manipulate here in code. (Message or Envelope.)
// a signed OTMessage
if (TYPE_1_CMD_1 == theCMD.fields.command_id)
{
#ifdef _WIN32
if (OTPAYLOAD_GetMessage(thePayload, theMessage))
#else
if (thePayload.GetMessage(theMessage))
#endif
{
OTLog::Output(2, "Successfully retrieved payload message...\n");
if (theMessage.ParseRawFile())
{
OTLog::Output(2, "Successfully parsed payload message.\n");
return true;
}
else {
OTLog::Error("Error parsing message.\n");
return false;
}
}
else {
OTLog::Error("Error retrieving message from payload.\n");
return false;
}
}
// A base64-encoded envelope, encrypted, and containing a signed message.
else if (TYPE_1_CMD_2 == theCMD.fields.command_id)
{
OTEnvelope theEnvelope;
if (thePayload.GetEnvelope(theEnvelope))
{
OTLog::Output(2, "Successfully retrieved envelope from payload...\n");
OTString strEnvelopeContents;
// Decrypt the Envelope.
if (m_pServer && theEnvelope.Open(m_pServer->GetServerNym(), strEnvelopeContents))
{
// All decrypted, now let's load the results into an OTMessage.
// No need to call theMessage.ParseRawFile() after, since
// LoadContractFromString handles it.
//
if (strEnvelopeContents.Exists() && theMessage.LoadContractFromString(strEnvelopeContents))
{
OTLog::Output(2, "Success loading message out of the envelope contents and parsing it.\n");
return true;
}
else
{
OTLog::Error("Error loading message from envelope contents.\n");
return false;
}
}
else
{
OTLog::Error("Unable to open envelope.\n");
return false;
}
}
else
{
OTLog::Error("Error retrieving message from payload.\n");
return false;
}
}
return true;
}
示例3: ProcessMessage_ZMQ
// true == YES, DISCONNECT m_pSocket, something must have gone wrong.
// false == NO, do NOT disconnect m_pSocket, everything went wonderfully!
//
bool ProcessMessage_ZMQ(OTServer & theServer, const std::string & str_Message, std::string & str_Reply)
{
if (str_Message.size() < 1)
return false;
const char * szFunc = "ProcessMessage_ZMQ";
// --------------------
// return value.
std::string resultString = ""; // Whatever we put in this string is what will get returned.
// First we grab the client's message
OTASCIIArmor ascMessage;
ascMessage.MemSet(str_Message.data(), str_Message.size());
// ------------------
//
// OTPayload thePayload;
// thePayload.SetPayloadSize(str_Message.size());
// memcpy((void*)thePayload.GetPayloadPointer(), str_Message.data(), str_Message.size());
// ----------------------------------------------------------------------
// OTLog::vError("Envelope: \n%s\n Size: %ld\n", ascMessage.Get(), ascMessage.GetLength());
bool bReturnVal = false; // "false" == no, do NOT disconnect. No errors. ("True" means YES, DISCONNECT!)
OTMessage theMsg, theReply; // we'll need these in a sec...
// OTEnvelope theEnvelope(ascMessage);
OTEnvelope theEnvelope;
if (false == theEnvelope.SetAsciiArmoredData(ascMessage))
{
OTLog::vError("%s: Error retrieving envelope.\n", szFunc);
bReturnVal = true; // disconnect the socket!
}
else
{ // Now the base64 is decoded and the envelope is in binary form again.
OTLog::vOutput(2, "%s: Successfully retrieved envelope from ZMQ message...\n", szFunc);
OTString strEnvelopeContents;
// OTString strPubkeyPath("TESTPUBKEY.txt");
// theServer.GetServerNym().SavePublicKey(strPubkeyPath);
// Decrypt the Envelope.
if (false == theEnvelope.Open(theServer.GetServerNym(), strEnvelopeContents)) // now strEnvelopeContents contains the decoded message.
{
OTLog::vError("%s: Unable to open envelope.\n", szFunc);
bReturnVal = true; // disconnect the socket!
}
else
{
// All decrypted--now let's load the results into an OTMessage.
// No need to call theMsg.ParseRawFile() after, since
// LoadContractFromString handles it.
//
if (strEnvelopeContents.Exists() && theMsg.LoadContractFromString(strEnvelopeContents))
{
theReply.m_strCommand.Format("@%s", theMsg.m_strCommand.Get());
theReply.m_strNymID = theMsg.m_strNymID; // UserID
theReply.m_strServerID = theMsg.m_strServerID; // ServerID, a hash of the server contract.
theReply.m_bSuccess = false; // The default reply. In fact this is probably superfluous.
// In case you want to see all the incoming messages...
// OTLog::vOutput(0, "%s\n\n", strEnvelopeContents.Get());
// By constructing this without a socket, I put it in ZMQ mode, instead of tcp/ssl.
OTClientConnection theClient(theServer);
// By optionally passing in &theClient, the client Nym's public key will be
// set on it whenever verification is complete. (So for the reply, I'll
// have the key and thus I'll be able to encrypt reply to the recipient.)
if (false == theServer.ProcessUserCommand(theMsg, theReply, &theClient))
{
const OTString s1(theMsg), s2(theReply);
OTLog::vOutput(0, "%s: Unable to process user command.\n\n ********** "
"REQUEST:\n\n%s\n\n ********** RESPONSE:\n\n%s\n\n", szFunc, s1.Get(), s2.Get());
// NOTE: normally you would even HAVE a true or false if we're in this block. ProcessUserCommand()
// is what tries to process a command and then sets false if/when it fails. Until that point, you
// wouldn't get any server reply. I'm now changing this slightly, so you still get a reply (defaulted
// to success==false.) That way if a client needs to re-sync his request number, he will get the false
// and therefore know to resync the # as his next move, vs being stuck with no server reply (and thus
// stuck with a bad socket.)
// We sign the reply here, but not in the else block, since it's already signed in cases where
// ProcessUserCommand() is a success, by the time that call returns.
theReply.m_bSuccess = false; // Since the process call definitely failed, I'm making sure this here is definitely set to false (even though it probably was already.)
theReply.SignContract(theServer.GetServerNym());
theReply.SaveContract();
}
else // At this point the reply is ready to go, and theClient has the public key of the recipient...
OTLog::vOutput(1, "%s: Successfully processed user command: %s.\n", szFunc, theMsg.m_strCommand.Get());
//.........这里部分代码省略.........