Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTKeypair Class Reference

#include <OTKeypair.hpp>

Public Member Functions

EXPORT bool MakeNewKeypair (int32_t nBits=1024)
 
EXPORT bool ReEncrypt (const OTPassword &theExportPassword, bool bImporting, OTString &strOutput)
 
EXPORT bool HasPublicKey ()
 
EXPORT bool HasPrivateKey ()
 
EXPORT const OTAsymmetricKeyGetPublicKey () const
 
EXPORT const OTAsymmetricKeyGetPrivateKey () const
 
EXPORT bool CalculateID (OTIdentifier &theOutput) const
 
EXPORT bool SaveCertToString (OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const
 
EXPORT bool SavePrivateKeyToString (OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const
 
EXPORT bool SaveCertAndPrivateKeyToString (OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool LoadPrivateKey (const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool LoadPublicKey (const OTString &strFoldername, const OTString &strFilename)
 
EXPORT bool LoadPrivateKeyFromCertString (const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool LoadPublicKeyFromCertString (const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool LoadPublicKeyFromCertFile (const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool LoadCertAndPrivateKeyFromString (const OTString &strInput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool LoadBothKeysFromCertFile (const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool SaveAndReloadBothKeysFromTempFile (OTString *pstrOutputCert=nullptr, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool GetPublicKey (OTASCIIArmor &strKey) const
 
EXPORT bool GetPublicKey (OTString &strKey, bool bEscaped=true) const
 
EXPORT bool SetPublicKey (const OTASCIIArmor &strKey)
 
EXPORT bool SetPublicKey (const OTString &strKey, bool bEscaped=false)
 
EXPORT bool GetPrivateKey (OTString &strKey, bool bEscaped=true) const
 
EXPORT bool GetPrivateKey (OTASCIIArmor &strKey) const
 
EXPORT bool SetPrivateKey (const OTString &strKey, bool bEscaped=false)
 
EXPORT bool SetPrivateKey (const OTASCIIArmor &strKey)
 
EXPORT bool SignContract (OTContract &theContract, const OTPasswordData *pPWData=nullptr)
 
EXPORT void SetMetadata (const OTSignatureMetadata &theMetadata)
 
EXPORT int32_t GetPublicKeyBySignature (listOfAsymmetricKeys &listOutput, const OTSignature &theSignature, bool bInclusive=false) const
 
EXPORT OTKeypair ()
 
EXPORT ~OTKeypair ()
 

Friends

class OTLowLevelKeyData
 

Detailed Description

Definition at line 192 of file OTKeypair.hpp.

Constructor & Destructor Documentation

opentxs::OTKeypair::OTKeypair ( )

Definition at line 184 of file OTKeypair.cpp.

185  : m_pkeyPublic(OTAsymmetricKey::KeyFactory())
186  , m_pkeyPrivate(OTAsymmetricKey::KeyFactory())
187 {
188 }
static EXPORT OTAsymmetricKey * KeyFactory()
opentxs::OTKeypair::~OTKeypair ( )

Definition at line 190 of file OTKeypair.cpp.

191 {
192 
193  if (nullptr != m_pkeyPublic) delete m_pkeyPublic; // todo: else error
194  m_pkeyPublic = nullptr;
195 
196  if (nullptr != m_pkeyPrivate) delete m_pkeyPrivate; // todo: else error
197  m_pkeyPrivate = nullptr;
198 }

Member Function Documentation

bool opentxs::OTKeypair::CalculateID ( OTIdentifier theOutput) const

Definition at line 643 of file OTKeypair.cpp.

644 {
645  OT_ASSERT(nullptr != m_pkeyPublic);
646 
647  return m_pkeyPublic->CalculateID(theOutput); // Only works for public keys.
648 }
virtual bool CalculateID(OTIdentifier &theOutput) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const OTAsymmetricKey & opentxs::OTKeypair::GetPrivateKey ( ) const

Definition at line 236 of file OTKeypair.cpp.

237 {
238  OT_ASSERT(nullptr != m_pkeyPrivate);
239 
240  return (*m_pkeyPrivate);
241 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::GetPrivateKey ( OTString strKey,
bool  bEscaped = true 
) const

Definition at line 568 of file OTKeypair.cpp.

569 {
570  OT_ASSERT(nullptr != m_pkeyPrivate);
571 
572  return m_pkeyPrivate->GetPrivateKey(strKey, bEscaped);
573 }
bool GetPrivateKey(OTString &strKey, bool bEscaped=true) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::GetPrivateKey ( OTASCIIArmor strKey) const

Definition at line 575 of file OTKeypair.cpp.

578 {
579  OT_ASSERT(nullptr != m_pkeyPrivate);
580 
581  return m_pkeyPrivate->GetPrivateKey(strKey);
582 }
bool GetPrivateKey(OTString &strKey, bool bEscaped=true) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const OTAsymmetricKey & opentxs::OTKeypair::GetPublicKey ( ) const

Definition at line 229 of file OTKeypair.cpp.

230 {
231  OT_ASSERT(nullptr != m_pkeyPublic);
232 
233  return (*m_pkeyPublic);
234 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::GetPublicKey ( OTASCIIArmor strKey) const

Definition at line 509 of file OTKeypair.cpp.

510 {
511  OT_ASSERT(nullptr != m_pkeyPublic);
512 
513  return m_pkeyPublic->GetPublicKey(strKey);
514 }
EXPORT bool GetPublicKey(OTASCIIArmor &strKey) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::GetPublicKey ( OTString strKey,
bool  bEscaped = true 
) const

Definition at line 516 of file OTKeypair.cpp.

517 {
518  OT_ASSERT(nullptr != m_pkeyPublic);
519 
520  return m_pkeyPublic->GetPublicKey(strKey, bEscaped);
521 }
EXPORT bool GetPublicKey(OTASCIIArmor &strKey) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
int32_t opentxs::OTKeypair::GetPublicKeyBySignature ( listOfAsymmetricKeys listOutput,
const OTSignature theSignature,
bool  bInclusive = false 
) const

Definition at line 650 of file OTKeypair.cpp.

654 {
655  OT_ASSERT(nullptr != m_pkeyPublic);
656  OT_ASSERT(nullptr != m_pkeyPublic->m_pMetadata);
657 
658  // We know that EITHER exact metadata matches must occur, and the signature
659  // MUST have metadata, (bInclusive=false)
660  // OR if bInclusive=true, we know that metadata is still used to eliminate
661  // keys where possible, but that otherwise,
662  // if the signature has no metadata, then the key is still returned, "just
663  // in case."
664  //
665  if ((false == bInclusive) &&
666  (false == theSignature.getMetaData().HasMetadata()))
667  return 0;
668 
669  // Below this point, metadata is used if it's available.
670  // It's assumed to be "okay" if it's not available, since any non-inclusive
671  // calls would have already returned by now, if that were the case.
672  // (But if it IS available, then it must match, or the key won't be
673  // returned.)
674  //
675  // If the signature has no metadata, or if m_pkeyPublic has no metadata, or
676  // if they BOTH have metadata, and their metadata is a MATCH...
677  if (!theSignature.getMetaData().HasMetadata() ||
678  !m_pkeyPublic->m_pMetadata->HasMetadata() ||
679  (m_pkeyPublic->m_pMetadata->HasMetadata() &&
680  theSignature.getMetaData().HasMetadata() &&
681  (theSignature.getMetaData() == *(m_pkeyPublic->m_pMetadata)))) {
682  // ...Then add m_pkeyPublic as a possible match, to listOutput.
683  //
684  listOutput.push_back(m_pkeyPublic);
685  return 1;
686  }
687  return 0;
688 }
OTSignatureMetadata * m_pMetadata
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::HasPrivateKey ( )

Definition at line 221 of file OTKeypair.cpp.

222 {
223  OT_ASSERT(nullptr != m_pkeyPrivate);
224 
225  return m_pkeyPrivate->IsPrivate(); // This means it actually has a private
226  // key in it, or tried to.
227 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::HasPublicKey ( )

Definition at line 213 of file OTKeypair.cpp.

214 {
215  OT_ASSERT(nullptr != m_pkeyPublic);
216 
217  return m_pkeyPublic->IsPublic(); // This means it actually has a public key
218  // in it, or tried to.
219 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::LoadBothKeysFromCertFile ( const OTString strFoldername,
const OTString strFilename,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 456 of file OTKeypair.cpp.

460 {
461  const char* szFunc = "OTKeypair::LoadBothKeysFromCertFile";
462 
463  OT_ASSERT(nullptr != m_pkeyPublic);
464  OT_ASSERT(nullptr != m_pkeyPrivate);
465 
466  bool bPublic = m_pkeyPublic->LoadPublicKeyFromCertFile(
467  strFoldername.Get(), strFilename.Get(), pstrReason, pImportPassword);
468  bool bPrivate = m_pkeyPrivate->LoadPrivateKey(
469  strFoldername.Get(), strFilename.Get(), pstrReason, pImportPassword);
470  if (!bPublic) {
471  otErr << szFunc << ": Although the ascii-armored file (" << strFilename
472  << ") was read, LoadPublicKeyFromCert "
473  "returned false.\n";
474  return false;
475  }
476  else {
477  otInfo << szFunc << ": Successfully loaded public key from Certfile: "
478  << strFilename << "\n";
479  }
480 
481  if (!bPrivate) {
482  otErr << szFunc << ": Although the ascii-armored file (" << strFilename
483  << ") was read, LoadPrivateKey returned false.\n";
484  return false;
485  }
486  else {
487  otInfo << szFunc << ": Successfully loaded private key from certfile: "
488  << strFilename << "\n";
489  }
490 
491  return true;
492 }
bool LoadPublicKeyFromCertFile(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otInfo
bool LoadPrivateKey(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTKeypair::LoadCertAndPrivateKeyFromString ( const OTString strInput,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 294 of file OTKeypair.cpp.

297 {
298  OT_ASSERT(strInput.Exists());
299 
300  // "escaped" means pre-pended with "- " as in: - -----BEGIN CER....
301  //
302  const bool bPublic = LoadPublicKeyFromCertString(
303  strInput, false, // bool bEscaped=true by default
304  pstrReason, pImportPassword);
305  const bool bPrivate = LoadPrivateKeyFromCertString(
306  strInput, false, // bool bEscaped=true by default,
307  pstrReason, pImportPassword);
308  if (!bPublic) {
309  otErr << __FUNCTION__
310  << ": Although the input string apparently exists, "
311  "LoadPublicKeyFromCertString returned false.\n";
312  return false;
313  }
314  else {
315  otInfo << __FUNCTION__
316  << ": Successfully loaded public key from string.\n";
317  }
318 
319  if (!bPrivate) {
320  otErr << __FUNCTION__
321  << ": Although the input string apparently exists, "
322  "LoadPrivateKeyFromCertString returned false.\n";
323  return false;
324  }
325  else {
326  otInfo << __FUNCTION__
327  << ": Successfully loaded private key from string.\n";
328  }
329 
330  return true;
331 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otInfo
EXPORT bool LoadPublicKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTKeypair.cpp:409
EXPORT bool LoadPrivateKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTKeypair.cpp:396
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTKeypair::LoadPrivateKey ( const OTString strFoldername,
const OTString strFilename,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 373 of file OTKeypair.cpp.

377 {
378  OT_ASSERT(nullptr != m_pkeyPrivate);
379 
380  return m_pkeyPrivate->LoadPrivateKey(strFoldername, strFilename, pstrReason,
381  pImportPassword);
382 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool LoadPrivateKey(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
bool opentxs::OTKeypair::LoadPrivateKeyFromCertString ( const OTString strCert,
bool  bEscaped = true,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 396 of file OTKeypair.cpp.

400 {
401  OT_ASSERT(nullptr != m_pkeyPrivate);
402 
403  return m_pkeyPrivate->LoadPrivateKeyFromCertString(
404  strCert, bEscaped, pstrReason, pImportPassword);
405 }
virtual bool LoadPrivateKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::LoadPublicKey ( const OTString strFoldername,
const OTString strFilename 
)

Definition at line 384 of file OTKeypair.cpp.

386 {
387  OT_ASSERT(nullptr != m_pkeyPublic);
388 
389  return m_pkeyPublic->LoadPublicKey(strFoldername, strFilename);
390 }
bool LoadPublicKey(const OTString &strFoldername, const OTString &strFilename)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::LoadPublicKeyFromCertFile ( const OTString strFoldername,
const OTString strFilename,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 419 of file OTKeypair.cpp.

423 {
424  OT_ASSERT(nullptr != m_pkeyPublic);
425 
426  return m_pkeyPublic->LoadPublicKeyFromCertFile(strFoldername, strFilename,
427  pstrReason, pImportPassword);
428 }
bool LoadPublicKeyFromCertFile(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::LoadPublicKeyFromCertString ( const OTString strCert,
bool  bEscaped = true,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 409 of file OTKeypair.cpp.

412 {
413  OT_ASSERT(nullptr != m_pkeyPublic);
414 
415  return m_pkeyPublic->LoadPublicKeyFromCertString(
416  strCert, bEscaped, pstrReason, pImportPassword);
417 }
virtual bool LoadPublicKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::MakeNewKeypair ( int32_t  nBits = 1024)

Definition at line 430 of file OTKeypair.cpp.

431 {
432  OT_ASSERT(nullptr != m_pkeyPrivate);
433  OT_ASSERT(nullptr != m_pkeyPublic);
434 
435  OTLowLevelKeyData lowLevelData;
436 
437  if (!lowLevelData.MakeNewKeypair(nBits)) {
438  otErr << "OTKeypair::MakeNewKeypair"
439  << ": Failed in a call to OTLowLevelKeyData::MakeNewKeypair("
440  << nBits << ").\n";
441  return false;
442  }
443 
444  return lowLevelData.SetOntoKeypair(*this);
445 
446  // If true is returned:
447  // Success! At this point, theKeypair's public and private keys have been
448  // set.
449  // Keep in mind though, they still won't be "quite right" until saved and
450  // loaded
451  // again, at least according to existing logic. That saving/reloading is
452  // currently
453  // performed in OTPseudonym::GenerateNym().
454 }
friend class OTLowLevelKeyData
Definition: OTKeypair.hpp:194
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTKeypair::ReEncrypt ( const OTPassword theExportPassword,
bool  bImporting,
OTString strOutput 
)

Definition at line 692 of file OTKeypair.cpp.

694 {
695 
696  OT_ASSERT(nullptr != m_pkeyPublic);
697  OT_ASSERT(nullptr != m_pkeyPrivate);
698 
701 
702  // If we were importing, we were in the exported format but now we're in the
703  // internal format.
704  // Therefore we want to use the wallet's internal cached master passphrase
705  // to save. Therefore
706  // strReason will be used for the import case.
707  //
708  // But if we were exporting, then we were in the internal format and just
709  // re-encrypted to the
710  // export format. So we'd want to pass the export passphrase when saving.
711  //
712  const OTString strReasonAbove(
713  bImporting ? "Enter the new export passphrase. (Above "
714  "ReEncryptPrivateKey in OTKeypair::ReEncrypt)"
715  : "Enter your wallet's master passphrase. (Above "
716  "ReEncryptPrivateKey in OTKeypair::ReEncrypt)");
717 
718  const OTString strReasonBelow(
719  bImporting ? "Enter your wallet's master passphrase. (Below "
720  "ReEncryptPrivateKey in OTKeypair::ReEncrypt)"
721  : "Enter the new export passphrase. (Below "
722  "ReEncryptPrivateKey in OTKeypair::ReEncrypt)");
723 
724  // At this point the public key was loaded from a public key, not a cert,
725  // but the private key was loaded from the cert. Therefore we'll save the
726  // public cert from the private key, and then use that to reload the public
727  // key after ReEncrypting. (Otherwise the public key would be there, but it
728  // would be missing the x509, which is only available in the cert, not the
729  // pubkey alone -- and without the x509 being there, the "SaveAndReload"
730  // call
731  // below would fail.
732  // Why don't I just stick the Cert itself into the public data, instead of
733  // sticking the public key in there? Because not all key credentials will
734  // use
735  // certs. Some will use pubkeys from certs, and some will use pubkeys not
736  // from
737  // certs. But I might still just stick it in there, and code things to be
738  // able to
739  // load either indiscriminately. After all, that's what I'm doing already in
740  // the
741  // asset and server contracts. But even in those cases, there will be times
742  // when
743  // only a pubkey is available, not a cert, so I'll probably still find
744  // myself having
745  // to do this. Hmm...
746 
747  const bool bReEncrypted = m_pkeyPrivate->ReEncryptPrivateKey(
748  theExportPassword, bImporting); // <==== IMPORT or EXPORT occurs here.
749  bool bGotCert = false;
750 
751  if (bReEncrypted) {
752 
753  // Keys won't be right until this happens. Todo: eliminate this need.
755  &strOutput, &strReasonBelow,
756  bImporting ? nullptr : &theExportPassword);
757  }
758 
759  const bool bSuccess = (bReEncrypted && bGotCert);
760 
761  if (!bSuccess) {
762  strOutput.Release();
763  otErr << __FUNCTION__ << ": Failure, either when re-encrypting, or "
764  "when subsequently retrieving "
765  "the public/private keys. bImporting == "
766  << (bImporting ? "true" : "false") << "\n";
767  }
768 
769  return bSuccess;
770 }
virtual bool ReEncryptPrivateKey(const OTPassword &theExportPassword, bool bImporting) const =0
EXPORT bool SaveAndReloadBothKeysFromTempFile(OTString *pstrOutputCert=nullptr, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTKeypair.cpp:333
EXPORT bool HasPublicKey()
Definition: OTKeypair.cpp:213
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
EXPORT bool HasPrivateKey()
Definition: OTKeypair.cpp:221
bool opentxs::OTKeypair::SaveAndReloadBothKeysFromTempFile ( OTString pstrOutputCert = nullptr,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 333 of file OTKeypair.cpp.

336 {
337  OT_ASSERT(nullptr != m_pkeyPrivate);
338  OT_ASSERT(nullptr != m_pkeyPublic);
339 
340  OTString strOutput;
341  const bool bSuccess =
342  SaveCertAndPrivateKeyToString(strOutput, pstrReason, pImportPassword);
343 
344  if (bSuccess) {
345  // todo security. Revisit this part during security audit.
346  //
347  const OTString strFilename("temp.nym"); // todo stop hardcoding. Plus
348  // this maybe should select a
349  // random number too.
350 
351  if (!OTDB::StorePlainString(strOutput.Get(), OTFolders::Cert().Get(),
352  strFilename.Get())) // temp.nym
353  {
354  otErr << __FUNCTION__
355  << ": Failure storing new cert in temp file: " << strFilename
356  << "\n";
357  return false;
358  }
359 
360  if (!LoadBothKeysFromCertFile(OTFolders::Cert().Get(), strFilename,
361  pstrReason, pImportPassword))
362  return false; // LoadBothKeysFromCertFile already has error logs, no
363  // need to log twice at this point.
364 
365  if (nullptr != pstrOutputCert)
366  pstrOutputCert->Set(strOutput); // Success!
367  }
368 
369  return bSuccess;
370 }
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:698
EXPORT bool LoadBothKeysFromCertFile(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTKeypair.cpp:456
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool SaveCertAndPrivateKeyToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTKeypair.cpp:277
static EXPORT const OTString & Cert()
Definition: OTFolders.cpp:299
bool opentxs::OTKeypair::SaveCertAndPrivateKeyToString ( OTString strOutput,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 277 of file OTKeypair.cpp.

280 {
281  OTString strCert, strPrivateKey;
282 
283  const bool bSaved1 = SaveCertToString(strCert, pstrReason, pImportPassword);
284  const bool bSaved2 =
285  SavePrivateKeyToString(strPrivateKey, pstrReason, pImportPassword);
286 
287  if (bSaved1 && bSaved2)
288  strOutput.Format(const_cast<char*>("%s%s"), strPrivateKey.Get(),
289  strCert.Get());
290 
291  return (bSaved1 && bSaved2);
292 }
EXPORT bool SavePrivateKeyToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const
Definition: OTKeypair.cpp:261
EXPORT bool SaveCertToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const
Definition: OTKeypair.cpp:243
bool opentxs::OTKeypair::SaveCertToString ( OTString strOutput,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
) const

Definition at line 243 of file OTKeypair.cpp.

246 {
247  OT_ASSERT(nullptr != m_pkeyPublic);
248 
249  OTString strCert,
250  strReason(nullptr == pstrReason ? "OTKeypair::SaveCertToString"
251  : pstrReason->Get());
252 
253  const bool bSaved =
254  m_pkeyPublic->SaveCertToString(strCert, &strReason, pImportPassword);
255 
256  if (bSaved) strOutput = strCert;
257 
258  return bSaved;
259 }
virtual bool SaveCertToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const =0
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::SavePrivateKeyToString ( OTString strOutput,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
) const

Definition at line 261 of file OTKeypair.cpp.

264 {
265  OT_ASSERT(nullptr != m_pkeyPrivate);
266 
267  OTString strPrivateKey;
268 
269  const bool bSaved = m_pkeyPrivate->SavePrivateKeyToString(
270  strPrivateKey, pstrReason, pImportPassword);
271 
272  if (bSaved) strOutput = strPrivateKey;
273 
274  return bSaved;
275 }
virtual bool SavePrivateKeyToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const =0
#define OT_ASSERT(x)
Definition: Assert.hpp:150
void opentxs::OTKeypair::SetMetadata ( const OTSignatureMetadata theMetadata)

Definition at line 200 of file OTKeypair.cpp.

201 {
202  OT_ASSERT(nullptr != m_pkeyPublic);
203  OT_ASSERT(nullptr != m_pkeyPrivate);
204  OT_ASSERT(nullptr != m_pkeyPublic->m_pMetadata);
205  OT_ASSERT(nullptr != m_pkeyPrivate->m_pMetadata);
206 
207  // Set it for both keys.
208  //
209  *(m_pkeyPublic->m_pMetadata) = theMetadata;
210  *(m_pkeyPrivate->m_pMetadata) = theMetadata;
211 }
OTSignatureMetadata * m_pMetadata
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::SetPrivateKey ( const OTString strKey,
bool  bEscaped = false 
)

Definition at line 588 of file OTKeypair.cpp.

589 {
590  OT_ASSERT(nullptr != m_pkeyPrivate);
591 
592  const char* szOverride = "PGP PRIVATE KEY";
593 
594  if (strKey.Contains(szOverride)) {
595  OTASCIIArmor theArmor;
596 
597  if (theArmor.LoadFromString(const_cast<OTString&>(strKey), bEscaped,
598  szOverride)) // szOverride == "PGP PRIVATE
599  // KEY"
600  {
601  // This function expects that the bookends are already removed.
602  // The ascii-armor loading code removes them and handles the escapes
603  // also.
604  // return
605  // m_pkeyPrivate->LoadPrivateKeyFromPGPKey(theArmor);
606  //
607  otOut << "OTKeypair::SetPrivateKey 1: Failure: PGP private keys "
608  "are NOT YET SUPPORTED.\n\n";
609  // otOut << "OTKeypair::SetPrivateKey 1: Failure: PGP
610  // private keys are NOT YET SUPPORTED:\n\n%s\n\n",
611  // strKey.Get());
612  return false;
613  }
614  else {
615  otOut << "OTKeypair::SetPrivateKey 2: Failure: PGP private keys "
616  "are NOT YET SUPPORTED.\n\n";
617  // otOut << "OTKeypair::SetPrivateKey 2: Failure: PGP
618  // private keys are NOT YET SUPPORTED:\n\n%s\n\n",
619  // strKey.Get());
620  return false;
621  }
622  }
623  else // the below function SetPrivateKey (in the return call) expects the
624  // bookends to still be there, and it will handle removing them. (Unlike
625  // PGP code above.)
626  //
627  return m_pkeyPrivate->SetPrivateKey(strKey, bEscaped);
628 }
OTLOG_IMPORT OTLogStream otOut
bool SetPrivateKey(const OTString &strKey, bool bEscaped=false)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::SetPrivateKey ( const OTASCIIArmor strKey)

Definition at line 630 of file OTKeypair.cpp.

637 {
638  OT_ASSERT(nullptr != m_pkeyPrivate);
639 
640  return m_pkeyPrivate->SetPrivateKey(strKey);
641 }
bool SetPrivateKey(const OTString &strKey, bool bEscaped=false)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::SetPublicKey ( const OTASCIIArmor strKey)

Definition at line 526 of file OTKeypair.cpp.

527 {
528  OT_ASSERT(nullptr != m_pkeyPublic);
529 
530  return m_pkeyPublic->SetPublicKey(strKey);
531 }
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTKeypair::SetPublicKey ( const OTString strKey,
bool  bEscaped = false 
)

Definition at line 538 of file OTKeypair.cpp.

539 {
540  OT_ASSERT(nullptr != m_pkeyPublic);
541 
542  if (strKey.Contains("PGP PUBLIC KEY")) {
543  OTASCIIArmor theArmor;
544 
545  if (theArmor.LoadFromString(const_cast<OTString&>(strKey), bEscaped)) {
546  // This function expects that the bookends are already removed.
547  // The ascii-armor loading code removes them and handles the escapes
548  // also.
549  return m_pkeyPublic->LoadPublicKeyFromPGPKey(theArmor);
550  }
551  else {
552  otInfo << "OTKeypair::SetPublicKey: Failed extracting PGP public "
553  "key from ascii-armored text.\n";
554  return false;
555  }
556  }
557  else // the below function SetPublicKey (in the return call) expects the
558  // bookends to still be there, and it will handle removing them. (Unlike
559  // PGP code above.)
560  return m_pkeyPublic->SetPublicKey(strKey, bEscaped);
561 }
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
virtual bool LoadPublicKeyFromPGPKey(const OTASCIIArmor &strKey)=0
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otInfo
bool opentxs::OTKeypair::SignContract ( OTContract theContract,
const OTPasswordData pPWData = nullptr 
)

Definition at line 494 of file OTKeypair.cpp.

496 {
497  OT_ASSERT(nullptr != m_pkeyPrivate);
498 
499  return theContract.SignWithKey(*m_pkeyPrivate, pPWData);
500 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150

Friends And Related Function Documentation

friend class OTLowLevelKeyData
friend

Definition at line 194 of file OTKeypair.hpp.


The documentation for this class was generated from the following files: