Skip to content

Commit 5af1376

Browse files
committed
code style improvements
1 parent 920cb94 commit 5af1376

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

code/PMSource.cpp

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,47 +34,42 @@ PMSource::PMSource(const PrivateMessage& pm)
3434
{
3535
const std::string uid_string = uintToString(pm.getFromUserID());
3636
const std::string::size_type origLen =
37-
pm.getDatestamp().length()+1
38-
+pm.getTitle().length()+1
39-
+pm.getFromUser().length()+1
40-
+uid_string.length()+1
41-
+pm.getToUser().length()+1
42-
+pm.getMessage().length()+1;
37+
pm.getDatestamp().length() + 1
38+
+ pm.getTitle().length() + 1
39+
+ pm.getFromUser().length() + 1
40+
+ uid_string.length() + 1
41+
+ pm.getToUser().length() + 1
42+
+ pm.getMessage().length() + 1;
4343
m_PaddingBuffer = new uint8_t[origLen];
4444
//copy datestamp
45-
uint64_t done = pm.getDatestamp().length()+1;
45+
uint64_t done = pm.getDatestamp().length() + 1;
4646
memcpy(&m_PaddingBuffer[0], pm.getDatestamp().c_str(), done);
4747
//copy title
48-
memcpy(&m_PaddingBuffer[done], pm.getTitle().c_str(), pm.getTitle().length()+1);
49-
done = done + pm.getTitle().length()+1;
48+
memcpy(&m_PaddingBuffer[done], pm.getTitle().c_str(), pm.getTitle().length() + 1);
49+
done = done + pm.getTitle().length() + 1;
5050
//copy fromUser
51-
memcpy(&m_PaddingBuffer[done], pm.getFromUser().c_str(), pm.getFromUser().length()+1);
52-
done = done + pm.getFromUser().length()+1;
51+
memcpy(&m_PaddingBuffer[done], pm.getFromUser().c_str(), pm.getFromUser().length() + 1);
52+
done = done + pm.getFromUser().length() + 1;
5353
//copy fromUserID
54-
memcpy(&m_PaddingBuffer[done], uid_string.c_str(), uid_string.length()+1);
55-
done = done + uid_string.length()+1;
54+
memcpy(&m_PaddingBuffer[done], uid_string.c_str(), uid_string.length() + 1);
55+
done = done + uid_string.length() + 1;
5656
//copy toUser
57-
memcpy(&m_PaddingBuffer[done], pm.getToUser().c_str(), pm.getToUser().length()+1);
58-
done = done + pm.getToUser().length()+1;
57+
memcpy(&m_PaddingBuffer[done], pm.getToUser().c_str(), pm.getToUser().length() + 1);
58+
done = done + pm.getToUser().length() + 1;
5959
//copy message
60-
memcpy(&m_PaddingBuffer[done], pm.getMessage().c_str(), pm.getMessage().length()+1);
61-
done = done + pm.getMessage().length()+1;
60+
memcpy(&m_PaddingBuffer[done], pm.getMessage().c_str(), pm.getMessage().length() + 1);
61+
done = done + pm.getMessage().length() + 1;
6262
#ifdef DEBUG
6363
if (done!=origLen)
6464
{
6565
std::cout << "Number of written bytes does not match expected number!\n";
6666
throw std::runtime_error("PMSource::PMSource(): Number of written bytes does not match expected number!");
6767
}
6868
#endif
69-
m_BufStream.buffer((const char*) m_PaddingBuffer, origLen);
69+
m_BufStream.buffer(reinterpret_cast<const char*>(m_PaddingBuffer), origLen);
7070
m_BitsRead = 0;
71-
//BufferStream takes care of pointer, so we set it to NULL here to avoid conflicts
72-
m_PaddingBuffer = NULL;
73-
}
74-
75-
PMSource::~PMSource()
76-
{
77-
//empty
71+
// BufferStream takes care of pointer, so we set it to NULL here to avoid conflicts.
72+
m_PaddingBuffer = nullptr;
7873
}
7974

8075
bool PMSource::getNextMessageBlock(MessageBlock& mBlock)
@@ -83,9 +78,9 @@ bool PMSource::getNextMessageBlock(MessageBlock& mBlock)
8378
switch (m_Status)
8479
{
8580
case psUnpadded:
86-
m_BufStream.read((char*) &(mBlock.words[0]), 64);
81+
m_BufStream.read(reinterpret_cast<char*>(&(mBlock.words[0])), 64);
8782
bytesRead = m_BufStream.gcount();
88-
if (bytesRead==64)
83+
if (bytesRead == 64)
8984
{
9085
m_BitsRead += 512;
9186
mBlock.reverseBlock();
@@ -100,7 +95,7 @@ bool PMSource::getNextMessageBlock(MessageBlock& mBlock)
10095
//zero out rest of message block
10196
memset(&(((uint8_t*) &(mBlock.words[0]))[bytesRead+1]), 0, 64 - (bytesRead+1));
10297
//pad size value in there, too, if possible
103-
if (bytesRead+1<=56)
98+
if (bytesRead + 1 <= 56)
10499
{
105100
#if BYTE_ORDER == LITTLE_ENDIAN
106101
reverse64(m_BitsRead, m_BitsRead);
@@ -115,9 +110,9 @@ bool PMSource::getNextMessageBlock(MessageBlock& mBlock)
115110
return true;
116111
break;
117112
case psPadded1024And512Read:
118-
//fill all with zeros (padding)
113+
// fill all with zeros (padding)
119114
memset(&(mBlock.words[0]), 0, 64);
120-
//pad size value in there, too
115+
// pad size value in there, too
121116
#if BYTE_ORDER == LITTLE_ENDIAN
122117
reverse64(m_BitsRead, m_BitsRead);
123118
#endif
@@ -135,10 +130,10 @@ bool PMSource::getNextMessageBlock(MessageBlock& mBlock)
135130
throw std::logic_error("PMSource::getNextMessageBlock(): Code execution should never get to this point!");
136131
return false;
137132
break;
138-
}//swi
133+
} // switch
139134
//We should never get to this point either!
140135
throw std::logic_error("PMSource::getNextMessageBlock(): Code execution should never get to this point either!");
141136
return false;
142137
}
143138

144-
} //namespace
139+
} // namespace

code/PMSource.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
namespace SHA256
2929
{
3030

31-
/** class that uses a PrivateMessage class instance as message source
32-
* for SHA-256 hash calculation
31+
/** Class that uses a PrivateMessage class instance as message source
32+
* for SHA-256 hash calculation.
3333
*/
3434
class PMSource: public MessageSource
3535
{
@@ -38,11 +38,7 @@ class PMSource: public MessageSource
3838
PMSource(const PrivateMessage& pm);
3939

4040

41-
/** destructor */
42-
virtual ~PMSource();
43-
44-
45-
/** \brief puts the next message block from the source in mBlock
41+
/** \brief Puts the next message block from the source in mBlock.
4642
*
4743
* \param mBlock reference to the message blocked that should be filled
4844
* \return Returns true, if there is at least one more message block.
@@ -52,8 +48,8 @@ class PMSource: public MessageSource
5248
virtual bool getNextMessageBlock(MessageBlock& mBlock);
5349
private:
5450
libstriezel::InBufferStream m_BufStream;
55-
}; //class
51+
}; // class
5652

57-
} //namespace
53+
} // namespace
5854

5955
#endif // PMSOURCE_HPP

libstriezel

Submodule libstriezel updated from bfbf96c to dfddd4e

0 commit comments

Comments
 (0)