Update reviewed Tizen::Io doxygen
[platform/framework/native/appfw.git] / inc / FSecCryptoISignature.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                        FSecCryptoISignature.h
20  * @brief               This is the header file for the %ISignature interface.
21  *
22  * This header file contains the declarations of the %ISignature interface.
23  */
24 #ifndef _FSEC_CRYPTO_ISIGNATURE_H_
25 #define _FSEC_CRYPTO_ISIGNATURE_H_
26
27 #include <FBaseString.h>
28 #include <FBaseByteBuffer.h>
29 #include <FSecIKey.h>
30
31 namespace Tizen { namespace Security { namespace Crypto
32 {
33
34 /**
35  *      @interface      ISignature
36  *      @brief          This interface provides the functionality of a digital signature algorithm.
37  *
38  *      @since          2.0
39  *
40  *      The %ISignature interface provides the functionality of a digital signature algorithm. @n
41  *
42  *      For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>. @n
43  *
44  *      The following example demonstrates how to use the %ISignature interface.
45  *
46  *  @code
47  *
48  *      void
49  *      MyClass::TestSignatureSample(void)
50  *      {
51  *              result r = E_FAILURE;
52  *              ISignature *pSignature = null;
53  *              IKeyPairGenerator *pKeyPairGen = null;
54  *              KeyPair *pKeyPair = null;
55  *              IPrivateKey *pPriKey = null;
56  *              IPublicKey *pPubKey = null;
57  *              ByteBuffer input;
58  *              ByteBuffer *pOutput = null;
59  *              ByteBuffer keyBytes;
60  *              ByteBuffer iv;
61  *              byte pArray[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'};
62  *              int size = 1024;
63  *              bool res = false;
64  *
65  *              r = input.Construct(16);
66  *              r = input.SetArray(pArray, 0, 16);
67  *              input.Flip();
68  *
69  *              pSignature = new RsaSignature();
70  *              if (pSignature == null)
71  *              {
72  *                      goto CATCH;
73  *              }
74  *
75  *              // Generates the key.
76  *              pKeyPairGen = new KeyPairGenerator();
77  *              if (pKeyPairGen == null)
78  *              {
79  *                      goto CATCH;
80  *              }
81  *
82  *              r = pKeyPairGen->Construct(size);
83  *              if (IsFailed(r))
84  *              {
85  *                      goto CATCH;
86  *              }
87  *
88  *              pKeyPair = pKeyPairGen->GenerateKeyPairN();
89  *              if (pKeyPair == null)
90  *              {
91  *                      goto CATCH;
92  *              }
93  *
94  *              pPubKey = pKeyPair->GetPublicKey();
95  *              if (pPubKey == null)
96  *              {
97  *                      goto CATCH;
98  *              }
99  *
100  *              pPriKey = pKeyPair->GetPrivateKey();
101  *              if (pPriKey == null)
102  *              {
103  *                      goto CATCH;
104  *              }
105  *
106  *              r = pSignature->SetPrivateKey(*pPriKey);
107  *              if (IsFailed(r))
108  *              {
109  *                      goto CATCH;
110  *              }
111  *
112  *              pOutput = pSignature->SignN(input);
113  *              if (pOutput == null)
114  *              {
115  *                      r = GetLastResult();
116  *                      goto CATCH;
117  *              }
118  *
119  *              r = pSignature->SetPublicKey(*pPubKey);
120  *              if (IsFailed(r))
121  *              {
122  *                      goto CATCH;
123  *              }
124  *
125  *              res = pSignature->Verify(input, *pOutput);
126  *              if (res == false)
127  *              {
128  *                      r = GetLastResult();
129  *                      goto CATCH;
130  *              }
131  *
132  *              r       = E_SUCCESS;
133  *
134  *  CATCH:
135  *              delete pSignature;
136  *              delete pOutput;
137  *              delete pKeyPairGen;
138  *              delete pKeyPair;
139  *   }
140  *
141  *  @endcode
142  */
143
144 class _OSP_EXPORT_ ISignature
145 {
146
147 public:
148         /**
149          * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes @n
150          * are called when the destructor of this interface is called.
151          *
152          *  @since              2.0
153          */
154         virtual ~ISignature(void) {}
155
156         /**
157          *      Sets an asymmetric private key for signature.
158          *
159          *      @since          2.0
160          *
161          *      @return         An error code
162          *      @param[in]      key                                                     An instance of IKey
163          *      @exception      E_SUCCESS                                       The method is successful.
164          *      @exception      E_INVALID_ARG                           The specified @c key is invalid.
165          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
166          */
167         virtual result SetPrivateKey(const Tizen::Security::IKey& key) = 0;
168
169         /**
170          *      Sets an asymmetric public key for verification.
171          *
172          *      @since          2.0
173          *
174          *      @return         An error code
175          *      @param[in]      key                                                     An instance of IKey
176          *      @exception      E_SUCCESS                                       The method is successful.
177          *      @exception      E_INVALID_ARG                           The specified @c key is invalid.
178          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
179          */
180         virtual result SetPublicKey(const Tizen::Security::IKey& key) = 0;
181
182         /**
183          *      Signs the data.
184          *
185          *      @since          2.0
186          *
187          *      @return         A pointer to the Tizen::Base::ByteBuffer instance that contains the output, @n
188          *                              else @c null if an error occurs
189          *      @param[in]      input                                           An instance of Tizen::Base::ByteBuffer
190          *      @exception      E_SUCCESS                                       The method is successful.
191          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
192          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
193          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
194          *      @exception      E_SYSTEM                                        A system error has occurred. @n
195          *                                                                                      The method has failed to operate with the openssl library, or
196          *                                                                                      the Tizen::Base::ByteBuffer operation has failed.
197          */
198         virtual Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input) = 0;
199
200         /**
201          *      Verifies the data. @n
202          *      The verification is done by comparing the @c signedData to the signature created by the @c data.
203          *
204          *      @since          2.0
205          *
206          *      @return         @c true if the signed data is correct, @n
207          *                              else @c false
208          *      @param[in]      data                                            An instance of Tizen::Base::ByteBuffer that contains the original data
209          *      @param[in]      signedData                                      An instance of Tizen::Base::ByteBuffer that contains the signed data
210          *      @exception      E_SUCCESS                                       The method is successful.
211          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
212          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
213          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
214          *      @exception      E_SYSTEM                                        A system error has occurred. @n
215          *                                                                                      The method has failed to operate with the openssl library, or
216          *                                                                                      the Tizen::Base::ByteBuffer operation has failed.
217          */
218         virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData) = 0;
219
220 protected:
221         //
222         //      This method is for internal use only. Using this method can cause behavioral, security-related,
223         //      and consistency-related issues in the application.
224         //
225         //      This method is reserved and may change its name at any time without prior notice.
226         //
227         //      @since 2.0
228         //
229         virtual void ISignature_Reserved1(void) {}
230
231 }; //ISignature
232
233 } } } //Tizen::Security::Crypto
234
235 #endif //_FSEC_CRYPTO_ISIGNATURE_H_