144 #if defined(OPENTXS_HAVE_NETINET_IN_H)
145 #include <netinet/in.h>
157 OTNym_or_SymmetricKey::OTNym_or_SymmetricKey()
160 , m_pPassword(nullptr)
161 , m_bCleanupPassword(false)
162 , m_pstrDisplay(nullptr)
176 if (m_bCleanupPassword && (
nullptr != m_pPassword))
delete m_pPassword;
177 m_pPassword =
nullptr;
179 m_pstrDisplay =
nullptr;
192 OTNym_or_SymmetricKey::OTNym_or_SymmetricKey(
196 m_pPassword(nullptr),
197 m_bCleanupPassword(false),
198 m_pstrDisplay(rhs.m_pstrDisplay)
207 m_pPassword = rhs.m_pPassword;
236 OTNym_or_SymmetricKey::OTNym_or_SymmetricKey(
241 m_pPassword(nullptr),
242 m_bCleanupPassword(false),
243 m_pstrDisplay(pstrDisplay)
247 OTNym_or_SymmetricKey::OTNym_or_SymmetricKey(
252 m_pPassword(nullptr),
253 m_bCleanupPassword(false),
254 m_pstrDisplay(pstrDisplay)
258 OTNym_or_SymmetricKey::OTNym_or_SymmetricKey(
264 , m_pPassword(const_cast<
OTPassword*>(&thePassword))
265 , m_bCleanupPassword(false)
266 , m_pstrDisplay(pstrDisplay)
272 if (&other !=
this) {
273 std::swap(m_pNym, other.m_pNym);
274 std::swap(m_pKey, other.m_pKey);
275 std::swap(m_pPassword, other.m_pPassword);
276 std::swap(m_bCleanupPassword, other.m_bCleanupPassword);
277 std::swap(m_pstrDisplay, other.m_pstrDisplay);
296 (m_pKey !=
nullptr));
308 if (
nullptr != m_pNym) {
313 if (
nullptr != m_pKey) m_pKey->
Release();
315 if (
nullptr != m_pPassword) {
318 if (m_bCleanupPassword)
322 m_pPassword =
nullptr;
334 return (idTHIS == idRHS);
373 const char* szFunc =
"OTNym_or_SymmetricKey::Open_or_Decrypt";
375 bool bSuccess =
false;
376 bool bHadToInstantiatePassword =
false;
382 bSuccess = (
const_cast<OTEnvelope&
>(inputEnvelope))
383 .Open(*(
GetNym()), strOutput);
395 (
nullptr == pstrDisplay) ? szFunc : pstrDisplay->
Get());
401 (
nullptr == m_pstrDisplay)
409 <<
": Failed trying to retrieve passphrase for key. "
410 "Returning false.\n";
416 bHadToInstantiatePassword =
true;
419 bSuccess = (
const_cast<OTEnvelope&
>(inputEnvelope))
420 .Decrypt(strOutput, *(
GetKey()), *pPassword);
423 if (bHadToInstantiatePassword) {
425 m_bCleanupPassword =
true;
426 m_pPassword = pPassword;
448 const char* szFunc =
"OTNym_or_SymmetricKey::Seal_or_Encrypt";
450 bool bSuccess =
false;
451 bool bHadToInstantiatePassword =
false;
456 bSuccess = outputEnvelope.
Seal(*(
GetNym()), strInput);
466 (
nullptr == pstrDisplay) ? szFunc : pstrDisplay->
Get());
472 (
nullptr == m_pstrDisplay)
480 <<
": Failed trying to retrieve passphrase for key. "
481 "Returning false.\n";
487 bHadToInstantiatePassword =
true;
490 bSuccess = outputEnvelope.
Encrypt(strInput, *(
GetKey()), *pPassword);
493 if (bHadToInstantiatePassword) {
495 m_bCleanupPassword =
true;
496 m_pPassword = pPassword;
EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetNym() const
EXPORT ~OTNym_or_SymmetricKey()
EXPORT void Release_Nym_or_SymmetricKey()
EXPORT bool Seal(const OTPseudonym &theRecipient, const OTString &theInput)
EXPORT bool Encrypt(const OTString &theInput, OTSymmetricKey &theKey, const OTPassword &thePassword)
EXPORT OTNym_or_SymmetricKey & operator=(OTNym_or_SymmetricKey other)
static EXPORT OTPassword * GetPassphraseFromUser(const OTString *pstrDisplay=nullptr, bool bAskTwice=false)
EXPORT bool Seal_or_Encrypt(OTEnvelope &outputEnvelope, const OTString &strInput, const OTString *pstrDisplay=nullptr)
EXPORT OTSymmetricKey * GetKey() const
EXPORT void swap(OTNym_or_SymmetricKey &other)
EXPORT const char * Get() const
EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
EXPORT OTPassword * GetPassword() const
virtual EXPORT void Release()
EXPORT bool IsNym() const
EXPORT bool CompareID(const OTNym_or_SymmetricKey &rhs) const
EXPORT bool HasPassword() const
EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
EXPORT bool IsKey() const
EXPORT bool Open_or_Decrypt(const OTEnvelope &inputEnvelope, OTString &strOutput, const OTString *pstrDisplay=nullptr)