Wolframe, 0.0.3

pwdChangeMessage.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _PASSWORD_CHANGE_MESSAGE_HPP_INCLUDED
37 #define _PASSWORD_CHANGE_MESSAGE_HPP_INCLUDED
38 
39 #include <string>
40 #include <cstring>
41 #include "crypto/md5.h"
42 
43 namespace _Wolframe {
44 namespace AAAA {
45 
48 {
49 private:
50  enum {
51  PASSWORD_MAX_LENGTH = 64 - sizeof( unsigned char ) - MD5_DIGEST_SIZE,
52  PAYLOAD_LENGTH = 64 - MD5_DIGEST_SIZE
53  };
54 
55  union {
56  unsigned char data[ 64 ];
57  struct {
58  unsigned char length;
60  unsigned char digest[ MD5_DIGEST_SIZE ];
61  } parts;
62  } m_message;
63 
64 public:
65  PasswordChangeMessage( const std::string& pwd );
66  PasswordChangeMessage( const unsigned char msg[ 64 ] );
67 
70  PasswordChangeMessage() { memset( m_message.data, 0, 64 ); }
71 
73 
74  void clear() { memset( m_message.data, 0, 64 ); }
75  unsigned char* data() { return m_message.data; }
76  std::size_t size() const { return sizeof( m_message.data ); }
77  std::string password() const { return std::string( m_message.parts.passwd,
78  m_message.parts.length ); }
79 
81  static bool isValid( const unsigned char buffer[ 64 ] )
82  { return isValid( buffer, 64u ); }
83  static bool isValid( const unsigned char buffer[], std::size_t size );
84 
86  bool isValid() const { return isValid( m_message.data, 64u ); }
87 
89  std::string toBase64( const unsigned char IV[ 16 ], const unsigned char key[ 32 ] ) const;
91  bool fromBase64( const std::string& msg,
92  const unsigned char IV[ 16 ], const unsigned char key[ 32 ] );
93 };
94 
95 }} // namespace _Wolframe::AAAA
96 
97 #endif // _PASSWORD_CHANGE_MESSAGE_HPP_INCLUDED
void clear()
Definition: pwdChangeMessage.hpp:74
char passwd[PASSWORD_MAX_LENGTH]
Definition: pwdChangeMessage.hpp:59
std::size_t size() const
Definition: pwdChangeMessage.hpp:76
bool fromBase64(const std::string &msg, const unsigned char IV[16], const unsigned char key[32])
Build the message from an encrypted base64 message.
unsigned char * data()
Definition: pwdChangeMessage.hpp:75
unsigned char length
Definition: pwdChangeMessage.hpp:58
~PasswordChangeMessage()
Definition: pwdChangeMessage.hpp:72
unsigned char digest[MD5_DIGEST_SIZE]
Definition: pwdChangeMessage.hpp:60
Password changer data structure.
Definition: pwdChangeMessage.hpp:47
struct _Wolframe::AAAA::PasswordChangeMessage::@1::@2 parts
std::string toBase64(const unsigned char IV[16], const unsigned char key[32]) const
Encrypt the message to a base64 string.
std::string password() const
Definition: pwdChangeMessage.hpp:77
static bool isValid(const unsigned char buffer[64])
Check if the buffer is a valid message.
Definition: pwdChangeMessage.hpp:81
PasswordChangeMessage()
Definition: pwdChangeMessage.hpp:70
union _Wolframe::AAAA::PasswordChangeMessage::@1 m_message
bool isValid() const
Check if the message is valid.
Definition: pwdChangeMessage.hpp:86