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


C++ OTPseudonym::GenerateNym方法代码示例

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


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

示例1: GenerateInternalNym

// ----------------------------------------------------
// INTERNAL NYM: For adding a PASSPHRASE to a PURSE.
//
// What if you DON'T want to encrypt the purse to your Nym??
// What if you just want to use a passphrase instead?
// That's what these functions are for. OT just generates
// a dummy Nym and stores it INSIDE THE PURSE. You set the
// passphrase for the dummy nym, and thereafter your 
// experience is one of a password-protected purse. (But
// in reality, there is a dummy nym inside that purse.)
//
bool OTPurse::GenerateInternalNym(int nBits/*=1024*/)
{
    // -------------------------------------------    
    if (this->IsUsingATempNym() || (NULL != this->GetInternalNym()))
    {
        OTLog::Output(0, "OTPurse::GenerateInternalNym: Failed: internal Nym already exists.\n");
        return false;
    }
    // -------------------------------------------    
    if (!this->IsEmpty())
    {
        OTLog::Output(0, "OTPurse::GenerateInternalNym: Failed: The purse must be EMPTY before you create a new dummy Nym, internal to that purse. (For the purposes of adding a passphrase to the purse, normally.)\n");
        return false;
    }
    // -------------------------------------------
    
    switch (nBits) 
    {
        case 1024: // todo hardcoding.
        case 2048:
        case 4096:
        case 8192:
            break;            
        default:
            OTLog::vError("OTPurse::GenerateInternalNym: Failure: nBits must be one of: "
                          "1024, 2048, 4096, 8192. (%d was passed...)\n", nBits);
            return false;
    }

    // -------------------------------------------
    OTPseudonym * pNym = new OTPseudonym;
	OT_ASSERT_MSG(NULL != pNym, "OTPurse::GenerateInternalNym: Assert: NULL != new OTPseudonym \n");
    // BELOW THIS point, pNym must either be deleted, or saved. (Or it will leak.)
	// --------------------------------------------
    
	if (false == pNym->GenerateNym(nBits, false)) // bCreateFile=true by default, but it's FALSE here.
	{
        OTLog::vOutput(0, "OTPurse::GenerateInternalNym: Failed while calling pNym->GenerateNym(%d, false).\n",
                       nBits);
		delete pNym;
		pNym = NULL;
        
        return false;
	}
    // ---------------------------------------------------
    
    const bool bSetIdentifier = pNym->SetIdentifierByPubkey();
    OT_ASSERT_MSG(bSetIdentifier, "OTPurse::GenerateInternalNym: Assert: pNym->SetIdentifierByPubkey() \n");

    // By this point, the Nym has been successfully generated, and he even has an ID!
    // Let's attach him to the purse so we don't have to keep worrying about a leak.
    //
    m_pTempNym = pNym;
    // ----------------------------
    // Let's make sure the new Nym's ID is also this purse's UserID...
    //
    pNym->GetIdentifier(m_UserID);
    
    m_bUsingTempNym    = true;
    m_bIsNymIDIncluded = true;
    
	return true;
}
开发者ID:CommonGoodFinance,项目名称:Open-Transactions,代码行数:74,代码来源:OTPurse.cpp


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