MD5Sum.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
23 #ifndef VARIANT_TOPIC_TOOLS_MD5_SUM_H
24 #define VARIANT_TOPIC_TOOLS_MD5_SUM_H
25 
26 #include <boost/array.hpp>
27 
28 #include <ros/ros.h>
29 
30 namespace variant_topic_tools {
36  class MD5Sum {
37  public:
40  typedef boost::array<uint32_t, 4> Digest;
41 
44  MD5Sum(const std::string& text = std::string());
45 
48  MD5Sum(const MD5Sum& src);
49 
52  ~MD5Sum();
53 
56  size_t getNumDigestedBits() const;
57 
60  Digest getDigest() const;
61 
64  void update(const std::string& text);
65 
68  void clear();
69 
72  void write(std::ostream& stream) const;
73 
76  std::string toString() const;
77 
80  MD5Sum& operator<<(const std::string& text);
81 
82  protected:
85  typedef boost::array<uint32_t, 2> Size;
86 
89  typedef boost::array<uint32_t, 16> Block;
90 
93  static const Digest initialDigest;
94 
98  static const boost::array<uint32_t, 64> numBitRotations;
99 
102  static const boost::array<uint32_t, 64> constants;
103 
106  static const Block padding;
107 
110  Digest digest;
111 
115 
118  Block buffer;
119 
122  void update(const uint8_t* bytes, size_t numBytes);
123 
126  static void transform(const Block& block, Digest& digest);
127 
130  static uint32_t rotateLeft(uint32_t value, size_t numBits);
131 
134  static void update(Digest& digest, Size& numDigestedBits, Block& buffer,
135  const uint8_t* bytes, size_t numBytes);
136 
139  static void finalize(Digest& digest, Size& numDigestedBits, Block& buffer);
140  };
141 
144  std::ostream& operator<<(std::ostream& stream, const MD5Sum& md5Sum);
145 };
146 
147 #endif
MD5Sum(const std::string &text=std::string())
Default constructor.
Definition: MD5Sum.cpp:68
boost::array< uint32_t, 4 > Digest
Definition of the MD5 sum digest type.
Definition: MD5Sum.h:40
MD5 sum computation algorithm.
Definition: MD5Sum.h:36
static const Block padding
Padding required to fill the last MD5 block for finalization.
Definition: MD5Sum.h:106
static uint32_t rotateLeft(uint32_t value, size_t numBits)
Perform bit rotation on a digest element.
Definition: MD5Sum.cpp:181
static void transform(const Block &block, Digest &digest)
Transform a block.
Definition: MD5Sum.cpp:142
void update(const std::string &text)
Update the MD5 sum using the given string.
Definition: MD5Sum.cpp:108
std::string toString() const
Convert the MD5 sum to a hexadecimal format string.
Definition: MD5Sum.cpp:128
boost::array< uint32_t, 16 > Block
Definition of the MD5 sum block type.
Definition: MD5Sum.h:89
void write(std::ostream &stream) const
Write the MD5 sum to a stream.
Definition: MD5Sum.cpp:124
Digest getDigest() const
Retrieve the MD5 sum&#39;s digest.
Definition: MD5Sum.cpp:94
Digest digest
The current digest.
Definition: MD5Sum.h:110
boost::array< uint32_t, 2 > Size
Definition of the MD5 sum size type.
Definition: MD5Sum.h:85
MD5Sum & operator<<(const std::string &text)
Stream operator for updating the MD5 sum.
Definition: MD5Sum.cpp:232
void clear()
Clear the MD5 sum.
Definition: MD5Sum.cpp:117
static const boost::array< uint32_t, 64 > constants
Constants according to the MD5 algorithm.
Definition: MD5Sum.h:102
Block buffer
The buffered bytes which did not fit into the last block.
Definition: MD5Sum.h:118
static void finalize(Digest &digest, Size &numDigestedBits, Block &buffer)
Compute the finalized digest.
Definition: MD5Sum.cpp:217
size_t getNumDigestedBits() const
Retrieve the MD5 sum&#39;s number of digested bits.
Definition: MD5Sum.cpp:86
static const Digest initialDigest
Initial digest.
Definition: MD5Sum.h:93
Size numDigestedBits
The number of digested bits.
Definition: MD5Sum.h:114
~MD5Sum()
Destructor.
Definition: MD5Sum.cpp:79
static const boost::array< uint32_t, 64 > numBitRotations
Number of bit rotations per round according to the MD5 algorithm.
Definition: MD5Sum.h:98


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49