156 #include <irrxml/irrXML.hpp>
182 , m_pOwner(&theOwner)
243 strAppendTo.
Concatenate(
"<masterPublic>\n%s</masterPublic>\n\n",
251 strAppendTo.
Concatenate(
"<publicContents count=\"%d\">\n\n",
258 "<publicInfo key=\"%s\">\n%s</publicInfo>\n\n",
259 it.first.c_str(), ascInfo.
Get());
273 "<publicCredential>\n%s</publicCredential>\n\n",
282 strAppendTo.
Concatenate(
"<privateContents count=\"%d\">\n\n",
289 "<privateInfo key=\"%s\">\n%s</privateInfo>\n\n",
290 it.first.c_str(), ascInfo.
Get());
301 "<subCredential nymID=\"%s\"\n"
302 " masterCredentialID=\"%s\" >\n\n",
346 int32_t nReturnVal = 0;
348 const OTString strNodeName(xml->getNodeName());
362 if (strNodeName.Compare(
"subCredential")) {
366 otWarn <<
"Loading subcredential...\n";
370 else if (strNodeName.Compare(
"nymIDSource")) {
371 otWarn <<
"Loading nymIDSource...\n";
375 otErr <<
"Error in " << __FILE__ <<
" line " << __LINE__
376 <<
": failed loading expected nymIDSource field.\n";
383 else if (strNodeName.Compare(
"masterPublic")) {
388 otErr <<
"Error in " << __FILE__ <<
" line " << __LINE__
389 <<
": failed loading expected master public credential while "
390 "loading subcredential.\n";
399 strMasterPublicCredential))) {
400 otErr <<
"Failure in " << __FILE__ <<
" line " << __LINE__
401 <<
": while loading subcredential: master public "
402 "credential loaded just now, doesn't match the actual "
403 "master public credential, "
404 "according to the current owner object.\n";
410 else if (strNodeName.Compare(
"publicContents")) {
412 strCount = xml->getAttributeValue(
"count");
413 const int32_t nCount = strCount.
Exists() ? atoi(strCount.
Get()) : 0;
415 int32_t nTempCount = nCount;
418 while (nTempCount-- > 0) {
420 const char* pElementExpected =
"publicInfo";
430 temp_MapAttributes.insert(std::pair<std::string, std::string>(
435 xml, strPublicInfo, pElementExpected,
436 &temp_MapAttributes))
438 otErr << __FUNCTION__ <<
": Error: Expected "
439 << pElementExpected <<
" element with text field.\n";
443 auto it = temp_MapAttributes.find(
"key");
444 if ((it != temp_MapAttributes.end()))
446 std::string& str_key = it->second;
452 mapPublic.insert(std::pair<std::string, std::string>(
453 str_key, strPublicInfo.
Get()));
460 otErr << __FUNCTION__
461 <<
": Expected key type of 'A' or 'E' or 'S'.\n";
466 otErr << __FUNCTION__
467 <<
": Strange error: couldn't find key type AT "
473 if (static_cast<int64_t>(mapPublic.size()) != nCount) {
474 otErr << __FUNCTION__ <<
", " << __FILE__ <<
", " << __LINE__
475 <<
": Subcredential expected to load " << nCount
476 <<
" publicInfo objects, "
477 "but actually loaded " << mapPublic.size()
478 <<
". (Mismatch, failure loading.)\n";
485 otErr << __FUNCTION__ <<
", " << __FILE__ <<
", " << __LINE__
486 <<
": Subcredential failed setting public contents while "
493 otInfo <<
"Loaded publicContents for subcredential.\n";
497 else if (strNodeName.Compare(
"publicCredential")) {
501 otErr <<
"Error in " << __FILE__ <<
" line " << __LINE__
502 <<
": failed loading expected public credential while "
503 "loading private subcredential.\n";
509 else if (strNodeName.Compare(
"privateContents")) {
511 strCount = xml->getAttributeValue(
"count");
512 const int32_t nCount = strCount.
Exists() ? atoi(strCount.
Get()) : 0;
514 int32_t nTempCount = nCount;
517 while (nTempCount-- > 0) {
519 const char* pElementExpected =
"privateInfo";
529 temp_MapAttributes.insert(std::pair<std::string, std::string>(
534 xml, strPrivateInfo, pElementExpected,
535 &temp_MapAttributes))
537 otErr << __FUNCTION__ <<
": Error: Expected "
538 << pElementExpected <<
" element with text field.\n";
542 auto it = temp_MapAttributes.find(
"key");
543 if ((it != temp_MapAttributes.end()))
545 std::string& str_key = it->second;
551 mapPrivate.insert(std::pair<std::string, std::string>(
552 str_key, strPrivateInfo.
Get()));
559 otErr << __FUNCTION__
560 <<
": Expected key type of 'A' or 'E' or 'S'.\n";
565 otErr << __FUNCTION__
566 <<
": Strange error: couldn't find key type AT "
572 if (static_cast<int64_t>(mapPrivate.size()) != nCount) {
573 otErr << __FUNCTION__ <<
", " << __FILE__ <<
", " << __LINE__
574 <<
": Subcredential expected to load " << nCount
575 <<
" privateInfo objects, "
576 "but actually loaded " << mapPrivate.size()
577 <<
". (Mismatch, failure loading.)\n";
613 otErr << __FUNCTION__ <<
", " << __FILE__ <<
", " << __LINE__
614 <<
": Subcredential failed setting private contents "
621 otInfo <<
"Loaded privateContents for subcredential.\n";
649 otOut << __FUNCTION__
650 <<
": Failure: When the NymID's source is hashed, the result "
651 "doesn't match the expected NymID.\n"
652 "Expected: " <<
m_strNymID <<
"\n Found: " << strNymID
677 otOut << __FUNCTION__
678 <<
": Failure: The actual master credential's NymID doesn't "
679 "match the NymID on this subcredential.\n"
691 const bool bCalcMasterCredID =
694 const OTString strActualMasterID(theActualMasterID);
697 otOut << __FUNCTION__
698 <<
": Failure: When the actual Master Credential is hashed, the "
699 "result doesn't match the expected Master Credential ID.\n"
701 <<
"\n Found: " << strActualMasterID <<
"\nMaster Cred:\n"
730 otOut << __FUNCTION__ <<
": Failure: This subcredential hasn't been "
731 "signed by its master credential.\n";
747 otWarn << __FUNCTION__ <<
": Failed verifying credential ID against "
748 "whatever it was expected to be.\n";
762 otErr << __FUNCTION__ <<
": Error calculating credential digest.\n";
769 "only be called on private "
std::map< std::string, std::string > Map
void UpdatePublicCredentialToString(OTString &strAppendTo)
EXPORT const OTAsymmetricKey & GetPublicKey() const
OTString m_strSourceForNymID
EXPORT bool CalculateDigest(const OTData &dataInput)
const OTString & GetContents() const
void SetOwner(OTCredential &theOwner)
const OTString & GetMasterCredID() const
void SetMasterCredID(const OTString &strMasterCredID)
OTString::Map m_mapPublicInfo
virtual bool VerifySignedByMaster()
virtual EXPORT bool VerifyContractID() const
virtual bool VerifyInternally()
virtual void UpdateContents()
OTLOG_IMPORT OTLogStream otOut
void UpdatePublicContentsToString(OTString &strAppendTo)
virtual bool SetPrivateContents(const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
void UpdateMasterPublicToString(OTString &strAppendTo)
OTString::Map m_mapPrivateInfo
virtual EXPORT void CalculateContractID(OTIdentifier &newID) const
EXPORT bool VerifyWithKey(const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr) const
EXPORT void Concatenate(const char *arg,...)
EXPORT bool Exists() const
EXPORT bool SetString(const OTString &theData, bool bLineBreaks=true)
const OTString & GetPriCredential() const
EXPORT bool Compare(const char *compare) const
void SetNymIDandSource(const OTString &strNymID, const OTString &strSourceForNymID)
virtual bool SaveContractWallet(std::ofstream &) const
static EXPORT bool LoadEncodedTextField(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
OTString m_strContractType
#define OT_ASSERT_MSG(x, s)
OTLOG_IMPORT OTLogStream otInfo
EXPORT const OTString & GetPubCredential() const
const OTString & GetNymID() const
virtual ~OTSubcredential()
virtual bool VerifyContract()
OTStringXML m_xmlUnsigned
OTLOG_IMPORT OTLogStream otWarn
const OTString & GetNymIDSource() const
EXPORT const char * Get() const
OTLOG_IMPORT OTLogStream otErr
void Release_Subcredential()
void UpdatePrivateContentsToString(OTString &strAppendTo)
EXPORT const OTPassword * GetImportPassword() const
EXPORT const OTMasterkey & GetMasterkey() const
virtual EXPORT void Release()
EXPORT const OTString & GetPubCredential() const
virtual bool SetPublicContents(const OTString::Map &mapPublic)
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
OTString m_strMasterCredID
EXPORT bool GetString(OTString &theData, bool bLineBreaks=true) const
virtual EXPORT void Release()
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
static bool LoadEncodedTextFieldByName(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)