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 {
77  DIGEST_SHA512
78  };
79 
80 public:
83 
85  RSASignature();
86 
88  RSASignature(const RSASignature& signatur);
89 
91  virtual ~RSASignature();
92 
94 
95 public:
98 
100 
102  template<typename Reflector>
103  void reflectRead(Reflector& r)
104  {
105  std::stringstream ss;
106  ss << (*this);
107  std::string str = ss.str();
108  r.delegate(str);
109  }
110 
111  template<typename Reflector>
112  void reflectWrite(Reflector& r)
113  {
114  std::string str;
115  r.delegate(str);
116  std::stringstream ss(str);
117  ss >> (*this);
118  }
119 
121 
122 public:
125 
127  RSASignature& operator=(const RSASignature& signature);
128 
130 
131 public:
134 
136  size_t getSize() const { return(mSize); }
137 
139  const uint8* getSignature() const { return(mData); }
140 
142 
143 public:
146 
155  static RSASignature signMessage(const RSAKey& iPrivateKey,
156  DigestType iDigestType,
157  const char* iMsg,
158  size_t iMsgLen);
159 
169  static bool verifyMessage(const RSAKey& iPublicKey,
170  DigestType iDigestType,
171  const char* iMsg,
172  size_t iMsgLen,
173  const RSASignature& iSignature);
174 
176 
177 private:
178  friend MIRA_BASE_EXPORT std::ostream& operator<<(std::ostream& stream,
179  const RSASignature& signature);
180  friend MIRA_BASE_EXPORT std::istream& operator>>(std::istream& stream,
181  RSASignature& signature);
182 
183 private:
184  size_t mSize;
185  uint8* mData;
186 };
187 
189 
197 MIRA_BASE_EXPORT std::ostream& operator<<(std::ostream& stream,
198  const RSASignature& signature);
199 
205 MIRA_BASE_EXPORT std::istream& operator>>(std::istream& stream,
206  RSASignature& signature);
207 
209 
210 template<typename SerializerTag>
211 class IsTransparentSerializable<RSASignature,SerializerTag> : public std::true_type {};
212 
214 
215 } // namespaces
216 
217 #endif
Typedefs for OS independent basic data types.
MIRA_SPLIT_REFLECT_MEMBER void reflectRead(Reflector &r)
Reflect.
Definition: RSASignature.h:103
Definition: RSASignature.h:75
size_t getSize() const
Return the size of the RSA signature.
Definition: RSASignature.h:136
Type trait that indicates whether a type should be serialized "transparently", i.e.
Definition: IsTransparentSerializable.h:81
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:112
MIRA_BASE_EXPORT std::istream & operator>>(std::istream &stream, RSAKey &key)
The &#39;>>&#39; operator for RSAKey.
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:139
Definition: RSASignature.h:76
#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.