sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FSecCryptoRsaSignature.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                FSecCryptoRsaSignature.h
20  * @brief               This is the header file for the %RsaSignature class.
21  *
22  * This header file contains the declarations of the %RsaSignature class.
23  */
24 #ifndef _FSEC_CRYPTO_RSA_SIGNATURE_H_
25 #define _FSEC_CRYPTO_RSA_SIGNATURE_H_
26
27 #include <FSecCryptoISignature.h>
28 #include <FBase.h>
29
30
31 namespace Tizen { namespace Security { namespace Crypto
32 {
33
34 /**
35  *      @class          RsaSignature
36  *      @brief          This class implements the Rivest Shamir Adleman (RSA) signatures.
37  *
38  *      @since          2.0
39  *
40  *      The %RsaSignature class implements the Rivest Shamir Adleman (RSA) signatures. @n
41  *
42  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
43  *
44  *      @see ISignature
45  *      @see IKeyPairGenerator
46  *      @see KeyPair
47  *      @see IPublicKey
48  *      @see IPrivateKey
49  *      @see PublicKey
50  *      @see PrivateKey
51  */
52 class _OSP_EXPORT_ RsaSignature
53         : public virtual ISignature
54         , public Tizen::Base::Object
55 {
56
57 public:
58         /**
59          *      This is the default constructor for this class.
60          *
61          *      @since          2.0
62          */
63         RsaSignature(void);
64
65         /**
66          *      This destructor overrides Tizen::Base::Object::~Object().
67          *
68          *      @since          2.0
69          */
70         virtual ~RsaSignature(void);
71
72         /**
73          *      Sets an asymmetric private key for signature.
74          *
75          *      @since          2.0
76          *
77          *      @return         An error code
78          *      @param[in]      key                                                     An instance of IKey
79          *      @exception      E_SUCCESS                                       The method is successful.
80          *      @exception      E_INVALID_ARG                           The specified @c key is invalid.
81          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
82          */
83         virtual result SetPrivateKey(const Tizen::Security::IKey& key);
84
85         /**
86          *      Sets an asymmetric public key for verification.
87          *
88          *      @since          2.0
89          *
90          *      @return         An error code
91          *      @param[in]      key                                                     An instance of IKey
92          *      @exception      E_SUCCESS                                       The method is successful.
93          *      @exception      E_INVALID_ARG                           The specified @c key is invalid.
94          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
95          */
96         virtual result SetPublicKey(const Tizen::Security::IKey& key);
97
98         /**
99          *      Signs the data.
100          *
101          *      @since          2.0
102          *
103          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
104          *                              else @c null if an error occurs
105          * @param[in]   input                                           An instance of Tizen::Base::ByteBuffer
106          *      @exception      E_SUCCESS                                       The method is successful.
107          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
108          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
109          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
110          *      @exception      E_SYSTEM                                        A system error has occurred. @n
111          *                                                                                      The method has failed to operate with the OpenSSL library, or
112          *                                                                                      the Tizen::Base::ByteBuffer operation has failed.
113          *  @remarks    The specific error code can be accessed using the GetLastResult() method.
114          */
115         virtual Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input);
116
117         /**
118          *      Verifies the data. @n
119          *      The verification is done by comparing the @c signedData to the signature created by the @c data.
120          *
121          *      @since          2.0
122          *
123          *      @return         @c true if the signed data is correct, @n
124          *                              else @c false
125          *      @param[in]      data                                            An instance of Tizen::Base::ByteBuffer that contains the original data
126          *      @param[in]      signedData                                      A instance of Tizen::Base::ByteBuffer that contains the signed data
127          *      @exception      E_SUCCESS                                       The method is successful.
128          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
129          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
130          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
131          *      @exception      E_SYSTEM                                        A system error has occurred. @n
132          *                                                                                      The method has failed to operate with the OpenSSL library, or
133          *                                                                                      the Tizen::Base::ByteBuffer operation has failed.
134          *  @remarks    The specific error code can be accessed using the GetLastResult() method.
135          */
136         virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData);
137
138 private:
139
140         //
141         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
142         //
143         // @since 2.0
144         //
145         RsaSignature(const RsaSignature& rhs);
146
147         //
148         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
149         //
150         // @since 2.0
151         //
152         RsaSignature& operator =(const RsaSignature& rhs);
153
154 private:
155         Tizen::Base::ByteBuffer __privateKey;
156         Tizen::Base::ByteBuffer __publicKey;
157
158         class _RsaSignatureImpl* __pRsaSignatureImpl;
159         friend class _RsaSignatureImpl;
160
161 }; //RsaSignature
162
163 } } } //Tizen::Security::Crypto
164
165 #endif //_FSEC_CRYPTO_RSA_SIGNATURE_H_