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


C++ CryptoKey::encodedPublicKey方法代码示例

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


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

示例1: buildRequestData

bool ContactRequestClient::buildRequestData(QByteArray cookie)
{
    /* [2*length][16*hostname][16*serverCookie][16*connSecret][data:pubkey][str:nick][str:message][data:signature] */
    QByteArray requestData;
    CommandDataParser request(&requestData);

    /* Hostname */
    QString hostname = user->hostname();
    hostname.truncate(hostname.lastIndexOf(QLatin1Char('.')));
    if (hostname.size() != 16)
    {
        qWarning() << "Cannot send contact request: unable to determine the remote service hostname";
        return false;
    }

    /* Connection secret */
    QByteArray connSecret = user->settings()->read<Base64Encode>("localSecret");
    if (connSecret.size() != 16)
    {
        qWarning() << "Cannot send contact request: invalid local secret";
        return false;
    }

    /* Public service key */
    Tor::HiddenService *service = user->identity->hiddenService();
    CryptoKey serviceKey;
    if (!service || !(serviceKey = service->cryptoKey()).isLoaded())
    {
        qWarning() << "Cannot send contact request: failed to load service key";
        return false;
    }

    QByteArray publicKeyData = serviceKey.encodedPublicKey();
    if (publicKeyData.isNull())
    {
        qWarning() << "Cannot send contact request: failed to encode service key";
        return false;
    }

    /* Build request */
    request << (quint16)0; /* placeholder for length */
    request.writeFixedData(hostname.toLatin1());
    request.writeFixedData(cookie);
    request.writeFixedData(connSecret);
    request.writeVariableData(publicKeyData);
    request << myNickname() << message();

    if (request.hasError())
    {
        qWarning() << "Cannot send contact request: command building failed";
        return false;
    }

    /* Sign request, excluding the length field */
    QByteArray signature = serviceKey.signData(requestData.mid(2));
    if (signature.isNull())
    {
        qWarning() << "Cannot send contact request: failed to sign request";
        return false;
    }

    request.writeVariableData(signature);
    if (request.hasError())
    {
        qWarning() << "Cannot send contact request: command building failed";
        return false;
    }

    /* Set length */
    qToBigEndian((quint16)requestData.size(), reinterpret_cast<uchar*>(requestData.data()));

    /* Send */
    qint64 re = socket->write(requestData);
    Q_ASSERT(re == requestData.size());
    Q_UNUSED(re);

    qDebug() << "Contact request for" << user->uniqueID << "sent request data";
    return true;
}
开发者ID:AlexTalker,项目名称:ricochet,代码行数:79,代码来源:ContactRequestClient.cpp


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