MIRA
RSASignature.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
48 #ifndef _MIRA_RSASIGNATURE_H_
49 #define _MIRA_RSASIGNATURE_H_
50 
51 #include <sstream>
52 
53 #include <platform/Types.h>
54 #include <error/Exceptions.h>
57 
58 #include <security/RSAKey.h>
59 
60 namespace mira {
61 
63 
70 {
71 public:
73  enum DigestType {
76  DIGEST_RIPEMD160
77  };
78 
79 public:
82 
84  RSASignature();
85 
87  RSASignature(const RSASignature& signatur);
88 
90  virtual ~RSASignature();
91 
93 
94 public:
97 
99 
101  template<typename Reflector>
102  void reflectRead(Reflector& r)
103  {
104  std::stringstream ss;
105  ss << (*this);
106  std::string str = ss.str();
107  r.delegate(str);
108  }
109 
110  template<typename Reflector>
111  void reflectWrite(Reflector& r)
112  {
113  std::string str;
114  r.delegate(str);
115  std::stringstream ss(str);
116  ss >> (*this);
117  }
118 
120 
121 public:
124 
126  RSASignature& operator=(const RSASignature& signature);
127 
129 
130 public:
133 
135  size_t getSize() const { return(mSize); }
136 
138  const uint8* getSignature() const { return(mData); }
139 
141 
142 public:
145 
154  static RSASignature signMessage(const RSAKey& iPrivateKey,
155  DigestType iDigestType,
156  const char* iMsg,
157  size_t iMsgLen);
158 
168  static bool verifyMessage(const RSAKey& iPublicKey,
169  DigestType iDigestType,
170  const char* iMsg,
171  size_t iMsgLen,
172  const RSASignature& iSignature);
173 
175 
176 private:
177  friend MIRA_BASE_EXPORT std::ostream& operator<<(std::ostream& stream,
178  const RSASignature& signature);
179  friend MIRA_BASE_EXPORT std::istream& operator>>(std::istream& stream,
180  RSASignature& signature);
181 
182 private:
183  size_t mSize;
184  uint8* mData;
185 };
186 
188 
196 MIRA_BASE_EXPORT std::ostream& operator<<(std::ostream& stream,
197  const RSASignature& signature);
198 
204 MIRA_BASE_EXPORT std::istream& operator>>(std::istream& stream,
205  RSASignature& signature);
206 
208 
209 template<typename SerializerTag>
210 class IsTransparentSerializable<RSASignature,SerializerTag> : public std::true_type {};
211 
213 
214 } // namespaces
215 
216 #endif
Typedefs for OS independent basic data types.
MIRA_SPLIT_REFLECT_MEMBER void reflectRead(Reflector &r)
Reflect.
Definition: RSASignature.h:102
Definition: RSASignature.h:75
size_t getSize() const
Return the size of the RSA signature.
Definition: RSASignature.h:135
Type trait that indicates whether a type should be serialized "transparently", i.e.
Definition: IsTransparentSerializable.h:81
IStream & operator>>(IStream &is, JSONValue &value)
Definition: JSON.h:389
Definition of a RSA key (public or private)
Definition: RSAKey.h:71
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
#define MIRA_SPLIT_REFLECT_MEMBER
Macro that insert a class member reflect() method just splitting reflection into a reflectRead() and ...
Definition: SplitReflect.h:238
void reflectWrite(Reflector &r)
Definition: RSASignature.h:111
Provides type trait that indicates whether a type should be serialized "transparently".
Provides MIRA_SPLIT_REFLECT macros.
std::ostream & operator<<(std::ostream &s, const LibraryVersion &version)
Definition: RSASignature.h:74
Commonly used exception classes.
DigestType
The digest type.
Definition: RSASignature.h:73
const uint8 * getSignature() const
Return the signature in a binary format.
Definition: RSASignature.h:138
#define MIRA_BASE_EXPORT
This is required because on windows there is a macro defined called ERROR.
Definition: Platform.h:153
A class for signing and verifying messages using a RSA key pair.
Definition: RSASignature.h:69
A class for a RSA key.