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


C++ Credential::asSerialized方法代码示例

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


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

示例1: Sign

bool PaymentCode::Sign(
    const uint32_t nym,
    const Credential& credential,
    proto::Signature& sig,
    const OTPasswordData* pPWData) const
{
    if (!pubkey_) {
        otErr << __FUNCTION__ << ": Payment code not instantiated.\n";
        return false;
    }

    serializedAsymmetricKey privatekey =
        App::Me().Crypto().BIP32().GetPaymentCode(nym);

    if (!privatekey) {
        otErr << __FUNCTION__ << ": Failed to derive private key for"
              << " payment code.\n";
        return false;
    }

    OTData existingKeyData, compareKeyData;
    serializedAsymmetricKey compareKey =
    App::Me().Crypto().BIP32().PrivateToPublic(*privatekey);
    compareKey->clear_path();

    std::dynamic_pointer_cast<AsymmetricKeySecp256k1>
        (pubkey_)->GetKey(existingKeyData);
    compareKeyData.Assign(compareKey->key().c_str(), compareKey->key().size());

    if (!(existingKeyData == compareKeyData)) {
        otErr << __FUNCTION__ << ": Private key is not valid for this"
        << " payment code.\n";
        return false;
    }
    std::unique_ptr<OTAsymmetricKey>
        signingKey(OTAsymmetricKey::KeyFactory(*privatekey));

        serializedCredential serialized = credential.asSerialized(
            Credential::AS_PUBLIC,
            Credential::WITHOUT_SIGNATURES);

    bool goodSig = signingKey->Sign(
        proto::ProtoAsData<proto::Credential>(*serialized),
        sig,
        pPWData,
        nullptr,
        ID(),
        proto::SIGROLE_NYMIDSOURCE);

    return goodSig;
}
开发者ID:bitcredit-currency,项目名称:opentxs,代码行数:51,代码来源:PaymentCode.cpp

示例2: Verify

bool MasterCredential::Verify(const Credential& credential) const
{
    serializedCredential serializedCred =
        credential.asSerialized(
            Credential::AS_PUBLIC,
            Credential::WITHOUT_SIGNATURES);

    if (!proto::Check<proto::Credential>(
        *serializedCred,
        0,
        0xFFFFFFFF,
        credential.Role(),
        false)) {
            otErr << __FUNCTION__ << ": Invalid credential syntax.\n";
            return false;
    }

    bool sameMaster = (id_ == credential.MasterID());

    if (!sameMaster) {
        otErr << __FUNCTION__ << ": Credential does not designate this"
              << " credential as its master.\n";
        return false;
    }

    SerializedSignature masterSig = credential.MasterSignature();

    if (!masterSig) {
        otErr << __FUNCTION__ << ": Missing master signature.\n";
        return false;
    }

    if (!m_SigningKey) {
        otErr << __FUNCTION__ << ": Master is missing signing keypair.\n";
        return false;
    }

    return m_SigningKey->Verify(
        proto::ProtoAsData<proto::Credential>(*serializedCred),
        *masterSig);
}
开发者ID:HRF92,项目名称:opentxs,代码行数:41,代码来源:MasterCredential.cpp


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