summaryrefslogtreecommitdiff
path: root/include/m_system_cpp.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/m_system_cpp.h')
-rw-r--r--include/m_system_cpp.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h
index a0679e496b..7d28b70d39 100644
--- a/include/m_system_cpp.h
+++ b/include/m_system_cpp.h
@@ -86,6 +86,37 @@ public:
__inline ~mir_cslock() { ::LeaveCriticalSection(&cs); }
};
+//////////////////////////////////////////////////////////////////////////////
+//pass_ptrA, pass_ptrW and pass_ptrT - automatic pointer for passwords
+
+class pass_ptrA : public mir_ptr<char>
+{
+public:
+ __inline explicit pass_ptrA() : mir_ptr(){}
+ __inline explicit pass_ptrA(char* _p) : mir_ptr(_p) {}
+ __inline ~pass_ptrA() { zero(); }
+ __inline char* operator = (char *_p){ zero(); mir_ptr::operator=(_p); }
+ __inline void zero()
+ { char *_data = mir_ptr::operator char *();
+ if (_data) SecureZeroMemory(_data, mir_strlen(_data));
+ }
+};
+
+class pass_ptrW : public mir_ptr<WCHAR>
+{
+public:
+ __inline explicit pass_ptrW() : mir_ptr(){}
+ __inline explicit pass_ptrW(WCHAR* _p) : mir_ptr(_p) {}
+ __inline ~pass_ptrW() { zero(); }
+ __inline WCHAR* operator = (WCHAR *_p){ zero(); mir_ptr::operator=(_p); }
+ __inline void zero()
+ { WCHAR *_data = mir_ptr::operator WCHAR *();
+ if (_data) SecureZeroMemory(_data, mir_wstrlen(_data)*sizeof(WCHAR));
+ }
+};
+
+typedef pass_ptrW pass_ptrT;
+
///////////////////////////////////////////////////////////////////////////////
// mir_cslockfull - controllable locker for the critical sections