Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[344439]: SecString.cpp Maximize Restore History

Download this file

SecString.cpp    220 lines (178 with data), 4.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/// \file MyString.cpp
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "PasswordSafe.h"
#include "SecString.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
SecString::~SecString()
{
trashstring();
}
void SecString::trashstring()
{
trashMemory((unsigned char*)m_mystring.GetBuffer(m_mystring.GetLength()),
m_mystring.GetLength());
}
LPTSTR SecString::GetBuffer(int nMinBufLength)
{
return m_mystring.GetBuffer(nMinBufLength);
}
void SecString::ReleaseBuffer(int nNewLength)
{
m_mystring.ReleaseBuffer(nNewLength);
}
int SecString::GetLength() const
{
return m_mystring.GetLength();
}
const SecString& SecString::operator=(const SecString& stringSrc)
{
trashstring();
m_mystring = stringSrc.m_mystring;
return *this;
}
const SecString& SecString::operator=(TCHAR ch)
{
trashstring();
m_mystring = ch;
return *this;
}
const SecString& SecString::operator=(LPCSTR lpsz)
{
trashstring();
m_mystring = lpsz;
return *this;
}
const SecString& SecString::operator=(LPCWSTR lpsz)
{
trashstring();
m_mystring = lpsz;
return *this;
}
const SecString& SecString::operator=(const unsigned char* psz)
{
trashstring();
m_mystring = psz;
return *this;
}
const SecString& SecString::operator+=(const SecString& string)
{
m_mystring += string.m_mystring;
return *this;
}
const SecString& SecString::operator+=(TCHAR ch)
{
m_mystring += ch;
return *this;
}
const SecString& SecString::operator+=(LPCTSTR lpsz)
{
m_mystring += lpsz;
return *this;
}
SecString AFXAPI operator+(const SecString& string1,const SecString& string2)
{
SecString s;
s = (SecString)(string1.m_mystring+string2.m_mystring);
return s;
}
SecString AFXAPI operator+(const SecString& string, TCHAR ch)
{
SecString s;
s = (SecString)(string.m_mystring + ch);
return s;
}
SecString AFXAPI operator+(TCHAR ch, const SecString& string)
{
SecString s;
s = (SecString)(ch + string.m_mystring);
return s;
}
SecString AFXAPI operator+(const SecString& string, LPCTSTR lpsz)
{
SecString s;
s = (SecString)(string.m_mystring + lpsz);
return s;
}
SecString AFXAPI operator+(LPCTSTR lpsz, const SecString& string)
{
SecString s;
s = (SecString)(lpsz + string.m_mystring);
return s;
}
SecString SecString::Mid(int nFirst, int nCount) const
{
return m_mystring.Mid(nFirst,nCount);
}
TCHAR SecString::operator[](int nIndex) const
{
return m_mystring[nIndex];
}
void SecString::SetAt(int nIndex, TCHAR ch)
{
m_mystring.SetAt(nIndex,ch);
}
SecString::operator CString() const
{
return m_mystring;
}
SecString::operator LPCTSTR() const
{
return (LPCTSTR)m_mystring;
}
BOOL SecString::IsEmpty() const
{
return m_mystring.IsEmpty();
}
BOOL SecString::LoadString(UINT nID)
{
return m_mystring.LoadString(nID);
}
int SecString::Find( TCHAR ch ) const
{
return m_mystring.Find(ch);
}
int SecString::Find( LPCTSTR lpszSub ) const
{
return m_mystring.Find(lpszSub);
}
//Can't properly trash the memory here, so it is better to just return a CString
CString SecString::Left( int nCount ) const
{
return m_mystring.Left(nCount);
}
//Can't properly trash the memory here, so it is better to just return a CString
CString SecString::Right( int nCount ) const
{
return m_mystring.Right(nCount);
}
bool operator==(const SecString& s1, const SecString& s2)
{
return s1.m_mystring==s2.m_mystring;
}
bool operator==(const SecString& s1, LPCTSTR s2)
{
return s1.m_mystring==s2;
}
bool operator==(LPCTSTR s1, const SecString& s2)
{
return s1==s2.m_mystring;
}
bool operator!=(const SecString& s1, const SecString& s2)
{
return s1.m_mystring!=s2.m_mystring;
}
bool operator!=(const SecString& s1, LPCTSTR s2)
{
return s1.m_mystring!=s2;
}
bool operator!=(LPCTSTR s1, const SecString& s2)
{
return s1!=s2.m_mystring;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------