本文整理汇总了C++中OTIdentifier类的典型用法代码示例。如果您正苦于以下问题:C++ OTIdentifier类的具体用法?C++ OTIdentifier怎么用?C++ OTIdentifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OTIdentifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: m_lLength
// This constructor gets the string version of the ID passed in,
// and sets that string on this object. (For when you need a string
// version of an ID.)
OTString::OTString(const OTIdentifier & theValue) : m_lLength(0), m_lPosition(0), m_strBuffer(NULL)
{
// Initialize();
if (theValue.GetSize() > 0)
theValue.GetString(*this);
}
示例2:
// This constructor gets the string version of the ID passed in,
// and sets that string on this object. (For when you need a string
// version of an ID.)
OTString::OTString(const OTIdentifier & theValue)
{
Initialize();
if (theValue.GetSize() > 0)
theValue.GetString(*this);
}
示例3: strAssetID
bool OTToken::RecordTokenAsSpent(OTString & theCleartextToken)
{
OTString strAssetID(GetAssetID());
// ----------------------------------------------------------------------------
// Calculate the filename (a hash of the Lucre cleartext token ID)
OTIdentifier theTokenHash;
theTokenHash.CalculateDigest(theCleartextToken);
// Grab the new hash into a string (for use as a filename)
OTString strTokenHash(theTokenHash);
OTString strAssetFolder;
strAssetFolder.Format("%s.%d", strAssetID.Get(), GetSeries());
// --------------------------------------------------------------------
// See if the spent token file ALREADY EXISTS...
bool bTokenIsPresent = OTDB::Exists(OTLog::SpentFolder(), strAssetFolder.Get(), strTokenHash.Get());
// If so, we're trying to record a token that was already recorded...
if (bTokenIsPresent)
{
OTLog::vError("OTToken::RecordTokenAsSpent: Trying to record token as spent,"
" but it was already recorded: %s%s%s%s%s\n",
OTLog::SpentFolder(), OTLog::PathSeparator(), strAssetFolder.Get(),
OTLog::PathSeparator(), strTokenHash.Get());
return false;
}
// ----------------------------------------------------------------------
// FINISHED:
// We actually save the token itself into the file, which is named based
// on a hash of the Lucre data.
// The success of that operation is also now the success of this one.
OTString strToken;
SaveContract(strToken);
bool bSaved = OTDB::StorePlainString(strToken.Get(), OTLog::SpentFolder(),
strAssetFolder.Get(), strTokenHash.Get());
if (!bSaved)
{
OTLog::vError("OTToken::RecordTokenAsSpent: Error saving file: %s%s%s%s%s\n",
OTLog::SpentFolder(), OTLog::PathSeparator(), strAssetFolder.Get(),
OTLog::PathSeparator(), strTokenHash.Get());
}
return bSaved;
}
示例4: XOR
// So we can implement the SAMY hash, which is currently an XOR of SHA-256 with WHRLPOOL
//
// Originally, it was SHA512 and WHRLPOOL, which both have a 512-bit output-size.
// I was then going to cut the result in half and XOR together again. But then I
// though, for now, instead of doing all that extra work, I'll just change the
// two "HashAlgorithms" from SHA512 and WHRLPOOL to SHA256 and WHIRLPOOL.
//
// This was very much easier, as I only had to change the little "512" to say
// "256" instead, and basically the job was done. Of course, this means that OT
// is generating a 256-bit hash in THIS object, and a 512-bit WHIRLPOOL hash in
// the other object. i.e. There is still one 512-bit hash that you are forced to
// calculate, even if you throw away half of it after the calculation is done.
//
// Since the main object has a 256-bit hash, the XOR() function below was already
// coded to XOR the minimum length based on the smallest of the two objects.
// Therefore, it will XOR 256 bits of the WHRLPOOL output into the 256 bits of
// the main output (SHA256) and stop there: we now have a 256 bit ID.
//
// The purpose here is to reduce the ID size so that it will work on Windows with
// the filenames. The current 512bit output is 64 bytes, or 128 characters when
// exported to a hex string (in all the OT contracts for example, over and over
// again.)
//
// The new size will be 256bit, which is 32 bytes of binary. In hex string that
// would be 64 characters. But we're also converting from Hex to Base62, which
// means we'll get it down to around 43 characters.
//
// This means our IDs are going to go from this:
//
//
// To this:
//
//
// You might ask: is 256 bits big enough of a hash size to be safe from collisions?
// Practically speaking, I believe so. The IDs are used for accounts, servers, asset types,
// and users. How many different asset types do you expect there will be, where changing the
// contract to anything still intelligible would result in a still-valid signature? To find
// a collision in a contract, where the signature would still work, would you expect the necessary
// changed plaintext to be something that would still make sense in the contract? Would such
// a random piece of data turn out to form proper XML?
//
// 256bits is enough to store the number of atoms in the Universe. If we ever need a bigger
// hashsize, just go change the HashAlgorithm1 back to "SHA512" instead of "SHA256", and you'll
// instantly have a doubled hash output size :-)
//
bool OTIdentifier::XOR(const OTIdentifier & theInput)
{
// Go with the smallest of the two
const int64_t lSize = (GetSize() > theInput.GetSize() ? theInput.GetSize() : GetSize());
for (int32_t i = 0; i < lSize; i++)
{
// When converting to BigInteger internally, this will be a bit more efficient.
((char*)GetPointer())[i] ^= ((char*)theInput.GetPointer())[i]; // todo cast
}
return true;
}
示例5: GetSenderAcctID
bool OTPayment::GetSenderAcctID(OTIdentifier & theOutput) const
{
theOutput.Release();
// ----------------------
if (!m_bAreTempValuesSet)
return false;
bool bSuccess = false;
switch (m_Type)
{
case OTPayment::CHEQUE:
case OTPayment::VOUCHER:
case OTPayment::INVOICE:
case OTPayment::PAYMENT_PLAN:
theOutput = m_SenderAcctID;
bSuccess = true;
break;
case OTPayment::SMART_CONTRACT:
case OTPayment::PURSE:
bSuccess = false;
break;
default:
OTLog::Error("OTPayment::GetSenderAcctID: Bad payment type!\n");
break;
}
return bSuccess;
}
示例6: GetOutboxHash
bool OTAccount::GetOutboxHash(OTIdentifier & theOutput)
{
theOutput.Release();
if (!m_OutboxHash.IsEmpty())
{
theOutput = m_OutboxHash;
return true;
}
else if (!GetUserID().IsEmpty() &&
!GetRealAccountID().IsEmpty() &&
!GetRealServerID().IsEmpty()
)
{
OTLedger theOutbox(GetUserID(), GetRealAccountID(), GetRealServerID());
if (theOutbox.LoadOutbox() && theOutbox.CalculateOutboxHash(theOutput))
{
SetOutboxHash(theOutput);
return true;
}
}
return false;
}
示例7: GetNymID
bool OTPurse::GetNymID(OTIdentifier & theOutput) const
{
bool bSuccess = false;
theOutput.Release();
// --------------------------------------
if (this->IsNymIDIncluded() && !m_UserID.IsEmpty())
{
bSuccess = true;
theOutput = m_UserID;
}
// --------------------------------------
else if (this->IsUsingATempNym() && (NULL != m_pTempNym))
{
bSuccess = true;
m_pTempNym->GetIdentifier(theOutput);
}
// --------------------------------------
else if (!m_UserID.IsEmpty())
{
bSuccess = true;
theOutput = m_UserID;
}
// --------------------------------------
return bSuccess;
}
示例8: CalculateDigest
// This method implements the SAMY hash
bool OTIdentifier::CalculateDigest(const OTData & dataInput)
{
//#ifndef ANDROID // SHA256 on Android; no whirlpool until OpenSSL 1.0.0 is added.
OTIdentifier idSecondHash;
if (idSecondHash.CalculateDigest(dataInput, HashAlgorithm2) &&
CalculateDigest(dataInput, HashAlgorithm1))
{
// At this point, we have successfully generated the WHRLPOOL hash in
// idSecondHash, and we've successfully generated the SHA-256 hash in
// this object.
// Next we XOR them together for the final product.
return XOR(idSecondHash);
}
//#else // ANDROID
// if (CalculateDigest(dataInput, HashAlgorithm1)) // SHA256 only until I add the new OpenSSL 1.0 for Android
// {
// return true;
// }
//#endif // ANDROID
return false;
}
示例9: CalculateDigest
// This method implements the SAMY hash
bool OTIdentifier::CalculateDigest(const OTString & strInput)
{
#ifndef ANDROID // If NOT Android...
OTIdentifier idSecondHash;
if (idSecondHash.CalculateDigest(strInput, HashAlgorithm2) &&
CalculateDigest(strInput, HashAlgorithm1))
{
// At this point, we have successfully generated the WHRLPOOL hash in
// idSecondHash, and we've successfully generated the SHA-256 hash in
// this object.
// Next we XOR them together for the final product.
return XOR(idSecondHash);
}
#else // SHA256 on Android; no whirlpool until OpenSSL 1.0.0 is added.
if (CalculateDigest(strInput, HashAlgorithm1))
{
return true;
}
#endif // ANDROID
return false;
}
示例10: CalculateContractID
// Most contracts calculate their ID by hashing the Raw File (signatures and all).
// The Basket only hashes the unsigned contents, and only with the account IDs removed.
// This way, the basket will produce a consistent ID across multiple different servers.
void OTBasket::CalculateContractID(OTIdentifier & newID)
{
const OTString strContents(m_xmlUnsigned);
// Produce a version of the file without account IDs (which are different from server to server.)
//
m_bHideAccountID = true;
UpdateContents(); // <=========
newID.CalculateDigest(m_xmlUnsigned);
// Put it back the way it was.
m_bHideAccountID = false;
// UpdateContents(); // No need to do this, we already had this string before (above).
m_xmlUnsigned = strContents; // Here we just set it back again.
}
示例11: GetRecipientAcctID
bool OTPayment::GetRecipientAcctID(OTIdentifier & theOutput) const
{
// NOTE:
// A cheque HAS NO "Recipient Asset Acct ID", since the recipient's account (where he deposits
// the cheque) is not known UNTIL the time of the deposit. It's certain not known at the time
// that the cheque is written...
theOutput.Release();
// ----------------------
if (!m_bAreTempValuesSet)
return false;
bool bSuccess = false;
switch (m_Type)
{
case OTPayment::PAYMENT_PLAN:
if (m_bHasRecipient)
{
theOutput = m_RecipientAcctID;
bSuccess = true;
}
else
bSuccess = false;
break;
case OTPayment::CHEQUE:
case OTPayment::VOUCHER:
case OTPayment::INVOICE:
case OTPayment::SMART_CONTRACT:
case OTPayment::PURSE: // A purse might have a recipient USER, but never a recipient ACCOUNT.
bSuccess = false;
break;
default:
OTLog::Error("OTPayment::GetRecipientAcctID: Bad payment type!\n");
break;
}
return bSuccess;
}
示例12: GetRemitterUserID
// With a voucher (cashier's cheque) the "bank" is the "sender",
// whereas the actual Nym who purchased it is the "remitter."
//
bool OTPayment::GetRemitterUserID(OTIdentifier & theOutput) const
{
theOutput.Release();
// ----------------------
if (!m_bAreTempValuesSet)
return false;
bool bSuccess = false;
switch (m_Type)
{
case OTPayment::VOUCHER:
theOutput = m_RemitterUserID;
bSuccess = true;
break;
default:
OTLog::Error("OTPayment::GetRemitterUserID: Bad payment type! Expected a voucher cheque.\n");
break;
}
return bSuccess;
}
示例13:
bool operator<(const OTIdentifier& lhs, const OTIdentifier& rhs)
{
return lhs.get() < rhs.get();
}
示例14: main
//.........这里部分代码省略.........
continue;
}
else if (strLine.compare(0,5,"clear") == 0)
{
if (NULL == g_pTemporaryNym)
{
OTLog::Output(0, "No Nym yet available. Try 'load'.\n");
continue;
}
g_pTemporaryNym->RemoveAllNumbers();
g_pTemporaryNym->SaveSignedNymfile(*g_pTemporaryNym);
OTLog::Output(0, "Successfully removed all issued and transaction numbers. Saving nym...\n");
continue;
}
else if (strLine.compare(0,7,"payment") == 0)
{
if (NULL == g_pTemporaryNym)
{
OTLog::Output(0, "No Nym yet available to sign the payment plan with. Try 'load'.\n");
continue;
}
OTLog::Output(0, "Enter your Asset Account ID that the payments will come from: ");
OTString strTemp;
strTemp.OTfgets(std::cin);
const OTIdentifier ACCOUNT_ID(strTemp), USER_ID(*g_pTemporaryNym);
OTAccount * pAccount = g_OT_API.GetWallet()->GetAccount(ACCOUNT_ID);
if (NULL == pAccount)
{
OTLog::Output(0, "That account isn't loaded right now. Try 'load'.\n");
continue;
}
// To write a payment plan, like a cheque, we need to burn one of our transaction numbers. (Presumably
// the wallet is also storing a couple of these, since they are needed to perform any transaction.)
//
// I don't have to contact the server to write a payment plan -- as long as I already have a transaction
// number I can use to write it. Otherwise I'd have to ask the server to send me one first.
OTString strServerID(pAccount->GetRealServerID());
long lTransactionNumber=0;
if (false == g_pTemporaryNym->GetNextTransactionNum(*g_pTemporaryNym, strServerID, lTransactionNumber))
{
OTLog::Output(0, "Payment Plans are written offline, but you still need a transaction number\n"
"(and you have none, currently.) Try using 'n' to request another transaction number.\n");
continue;
}
// -----------------------------------------------------------------------
OTString str_RECIPIENT_USER_ID, str_RECIPIENT_ACCT_ID, strConsideration;
// Get the Recipient Nym ID
OTLog::Output(0, "Enter the Recipient's User ID (NymID): ");
str_RECIPIENT_USER_ID.OTfgets(std::cin);
示例15: strAssetTypeID
_SharedPtr<OTAccount> OTAcctList::GetOrCreateAccount(OTPseudonym & theServerNym,
const OTIdentifier & ACCOUNT_OWNER_ID,
const OTIdentifier & ASSET_TYPE_ID,
const OTIdentifier & SERVER_ID,
bool & bWasAcctCreated, // this will be set to true if the acct is created here. Otherwise set to false;
const int64_t lStashTransNum/*=0*/)
{
_SharedPtr<OTAccount> pRetVal;
bWasAcctCreated = false;
// ------------------------------------------------
if (OTAccount::stash == m_AcctType)
{
if (lStashTransNum <= 0)
{
OTLog::Error("OTAcctList::GetOrCreateAccount: Failed attempt to create stash account without cron item #.\n");
return pRetVal;
}
}
// ------------------------------------------------
// First, we'll see if there's already an account ID available for the requested asset type ID.
//
const OTString strAssetTypeID(ASSET_TYPE_ID);
const std::string str_asset_type_id = strAssetTypeID.Get();
// ------------------------------------
OTString strAcctType;
TranslateAccountTypeToString(m_AcctType, strAcctType);
// ----------------------------------------------------------------
mapOfStrings::iterator it_acct_ids = m_mapAcctIDs.find(str_asset_type_id);
if (m_mapAcctIDs.end() != it_acct_ids) // Account ID *IS* already there for this asset type...
{
const std::string str_account_id = (*it_acct_ids).second; // grab account ID
mapOfWeakAccounts::iterator it_weak = m_mapWeakAccts.find(str_account_id); // Try to find account pointer...
if (m_mapWeakAccts.end() != it_weak) // FOUND the weak ptr to the account! Maybe it's already loaded
{
// bool bSuccess = true;
_WeakPtr<OTAccount> pWeak = (*it_weak).second; // first is acct ID, second is weak_ptr to account.
try
{
_SharedPtr<OTAccount> pShared(pWeak);
// If success, then we have a shared pointer. But it's worrying (TODO) because this should have
// gone out of scope and been destroyed by whoever ELSE was using it. The fact that it's still here...
// well I'm glad not to double-load it, but I wonder why it's still here? And we aren't walking on anyone's
// toes, right? If this were multi-threaded, then I'd explicitly lock a mutex here, honestly. But since things
// happen one at a time on OT, I'll settle for a warning for now. I'm assuming that if the account's loaded
// already somewhere, it's just a pointer sitting there, and we're not walking on each other's toes.
//
if (pShared)
{
OTLog::vOutput(0, "OTAcctList::GetOrCreateAccount: Warning: account (%s) was already in memory so I gave you a "
"pointer to the existing one. (But who else has a copy of it?) \n", str_account_id.c_str());
return pShared;
}
}
catch (...)
{
}
// Though the weak pointer was there, the resource must have since been destroyed,
// because I cannot lock a new shared ptr onto it. :-(
//
// Therefore remove it from the map, and RE-LOAD IT.
//
m_mapWeakAccts.erase(it_weak);
}
// DIDN'T find the acct pointer, even though we had the ID.
// (Or it was there, but we couldn't lock a shared_ptr onto it, so we erased it...)
//
// So let's load it now. After all, the Account ID *does* exist...
//
const OTString strAcctID(str_account_id.c_str());
const OTIdentifier theAccountID(strAcctID);
// The Account ID exists, but we don't have the pointer to a loaded account for it.
// Soo.... let's load it.
//
OTAccount * pAccount = OTAccount::LoadExistingAccount(theAccountID, SERVER_ID);
if (NULL == pAccount)
OTLog::vError("OTAcctList::GetOrCreateAccount: Failed trying to load %s account with account ID: %s\n",
strAcctType.Get(),strAcctID.Get());
else if (!pAccount->VerifySignature(theServerNym))
OTLog::vError("OTAcctList::GetOrCreateAccount: Failed verifying server's signature on %s account with account ID: %s\n",
strAcctType.Get(),strAcctID.Get());
else if (!pAccount->VerifyOwnerByID(ACCOUNT_OWNER_ID))
{
const OTString strOwnerID(ACCOUNT_OWNER_ID);
OTLog::vError("OTAcctList::GetOrCreateAccount: Failed verifying owner ID (%s) on %s account ID: %s\n",
strOwnerID.Get(), strAcctType.Get(),strAcctID.Get());
}
//.........这里部分代码省略.........