当前位置: 首页>>代码示例>>C++>>正文


C++ DocumentPtr::parse方法代码示例

本文整理汇总了C++中DocumentPtr::parse方法的典型用法代码示例。如果您正苦于以下问题:C++ DocumentPtr::parse方法的具体用法?C++ DocumentPtr::parse怎么用?C++ DocumentPtr::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DocumentPtr的用法示例。


在下文中一共展示了DocumentPtr::parse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getPrivateProfile

      //---------------------------------------------------------------------
      ElementPtr PeerContactProfile::getPrivateProfile() const
      {
        AutoRecursiveLock lock(mLock);
        if (!mDocument) return ElementPtr();
        if (!hasContactProfileSecret()) return ElementPtr();

        try {
          ElementPtr contactProfileElement = getContactProfileElement();
          if (!contactProfileElement) return ElementPtr();
          ElementPtr privateElement = contactProfileElement->findFirstChildElementChecked("private");
          ElementPtr profileElement = privateElement->findFirstChildElementChecked("encryptedProfile");
          ElementPtr saltElement = privateElement->findFirstChildElementChecked("salt");

          String saltAsBase64 = saltElement->getText(true);

          SecureByteBlock output;
          decryptAndNulTerminateFromBase64(
                                           "profile",
                                           mContactProfileSecret,
                                           saltAsBase64,
                                           profileElement->getText(true),
                                           output
                                           );

          String parseData = (CSTR)((const BYTE *)output);
          DocumentPtr temp = Document::create();
          temp->parse(parseData);
          ElementPtr result = temp->findFirstChildElementChecked("profile");
          result->orphan();
          return result;
        } catch (zsLib::XML::Exceptions::CheckFailed &) {
        }
        return ElementPtr();
      }
开发者ID:Gurtej,项目名称:op,代码行数:35,代码来源:stack_PeerContactProfile.cpp

示例2: getPeerFilePublic

      //---------------------------------------------------------------------
      IPeerFilePublicPtr PeerContactProfile::getPeerFilePublic() const
      {
        AutoRecursiveLock lock(mLock);
        PeerFilesPtr outer = mPeerFiles.lock();
        if (outer) {
          IPeerFilePublicPtr publicPeer = outer->getPublic();
          if (publicPeer) return publicPeer;
        }

        if (!mDocument) return IPeerFilePublicPtr();
        if (!hasContactProfileSecret()) return IPeerFilePublicPtr();

        try {
          ElementPtr contactProfileElement = getContactProfileElement();
          if (!contactProfileElement) return IPeerFilePublicPtr();
          ElementPtr privateElement = contactProfileElement->findFirstChildElementChecked("private");
          ElementPtr encryptedPeerElement = privateElement->findFirstChildElementChecked("encryptedPeer");
          ElementPtr saltElement = privateElement->findFirstChildElementChecked("salt");

          String saltAsBase64 = saltElement->getText(true);

          SecureByteBlock output;
          decryptAndNulTerminateFromBase64(
                                           "peer",
                                           mContactProfileSecret,
                                           saltAsBase64,
                                           encryptedPeerElement->getText(true),
                                           output
                                           );

          String parseData = (CSTR)((const BYTE *)output);
          DocumentPtr temp = Document::create();
          temp->parse(parseData);
          ElementPtr result = temp->findFirstChildElementChecked("peer");
          result->orphan();

          PeerFilePublicPtr publicPeer = PeerFilePublic::loadFromXML(result);
          return publicPeer;
        } catch (zsLib::XML::Exceptions::CheckFailed &) {
        }
        return IPeerFilePublicPtr();
      }
开发者ID:Gurtej,项目名称:op,代码行数:43,代码来源:stack_PeerContactProfile.cpp

示例3: createExternalFromPrivateProfile

      //---------------------------------------------------------------------
      PeerContactProfilePtr PeerContactProfile::createExternalFromPrivateProfile(ElementPtr privateProfileElement)
      {
        if (!privateProfileElement) return PeerContactProfilePtr();

        privateProfileElement = (privateProfileElement->clone())->toElementChecked();

        static const char *contactProfileSkeleton =
        "<contactProfile version=\"0\">\n"
        " <private>\n"
        "  <salt />\n"
        "  <proof cipher=\"sha256/aes256\" />\n"
        "  <encryptedProfile cipher=\"sha256/aes256\" />\n"
        "  <contactProfileSecret cipher=\"sha256/aes256\" />\n"
        " </private>\n"
        "</contactProfile>";

        DocumentPtr contactProfileDoc = Document::create();
        contactProfileDoc->parse(contactProfileSkeleton);

        String contactID = services::IHelper::randomString(32);
        String contactProfileSecret = services::IHelper::randomString(32);

        // generate external profile
        {
          std::string contactSalt;

          // generate salt
          {
            AutoSeededRandomPool rng;

            SecureByteBlock contactSaltRaw(32);
            rng.GenerateBlock(contactSaltRaw, contactSaltRaw.size());
            contactSalt = convertToBase64(contactSaltRaw, contactSaltRaw.size());
          }

          ElementPtr contactProfileElement = contactProfileDoc->getFirstChildElementChecked();
          contactProfileElement->setAttribute("id", contactID);

          ElementPtr privateElement = contactProfileElement->getFirstChildElementChecked();
          ElementPtr saltElement = privateElement->getFirstChildElementChecked();
          TextPtr saltText = Text::create();
          saltText->setValue(contactSalt);
          saltElement->adoptAsLastChild(saltText);

          SecureByteBlock contactProofHash(32);

          SHA256 contactProof;
          contactProof.Update((const BYTE *)"proof:", strlen("proof:"));
          contactProof.Update((const BYTE *)contactProfileSecret.c_str(), contactProfileSecret.size());
          contactProof.Final(contactProofHash);

          String contactProofInBase64 = convertToBase64(contactProofHash, contactProofHash.size());

          ElementPtr proofElement = saltElement->getNextSiblingElementChecked();
          TextPtr proofText = Text::create();
          proofText->setValue(contactProofInBase64);
          proofElement->adoptAsLastChild(proofText);

          DocumentPtr privateProfileDocument = Document::create();
          privateProfileDocument->adoptAsLastChild(privateProfileElement);

          ULONG length = 0;
          boost::shared_array<char> output;
          output = privateProfileDocument->write(&length);

          ElementPtr encryptedProfileElement = proofElement->getNextSiblingElementChecked();
          String encryptedProfileString = encryptToBase64("profile", contactProfileSecret, contactSalt, (const BYTE *)(output.get()), length);
          TextPtr encryptProfileText = Text::create();
          encryptProfileText->setValue(encryptedProfileString);
          encryptedProfileElement->adoptAsLastChild(encryptProfileText);

          ElementPtr contactProfileSecretElement = encryptedProfileElement->getNextSiblingElementChecked();
          TextPtr contactProfileSecretText = Text::create();
          contactProfileSecretText->setValue(contactProfileSecret);
          contactProfileSecretElement->adoptAsLastChild(contactProfileSecretText);
        }

        PeerContactProfilePtr pThis(new PeerContactProfile);
        pThis->mThisWeak = pThis;
        pThis->mDocument = contactProfileDoc;
        pThis->mContactProfileSecret = contactProfileSecret;
        return pThis;
      }
开发者ID:Gurtej,项目名称:op,代码行数:84,代码来源:stack_PeerContactProfile.cpp


注:本文中的DocumentPtr::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。