本文整理汇总了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;
}
示例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);
}