Merge "Update GetPackageAppInfoN() API" into tizen_2.1
[platform/framework/native/appfw.git] / inc / FSecCryptoSha1Hmac.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                FSecCryptoSha1Hmac.h
20  * @brief               This is the header file for the %Sha1Hmac class.
21  *
22  * This header file contains the declarations of the %Sha1Hmac class.
23  */
24 #ifndef _FSEC_CRYPTO_SHA1_HMAC_H_
25 #define _FSEC_CRYPTO_SHA1_HMAC_H_
26
27 #include <FSecCryptoIHmac.h>
28
29 struct hmac_ctx_st;
30
31
32 namespace Tizen { namespace Security { namespace Crypto
33 {
34
35 /**
36  *      @class          Sha1Hmac
37  *      @brief          This class implements the SHA-1 HMAC algorithm.
38  *
39  *      @since          2.0
40  *
41  *      The %Sha1Hmac class implements the SHA-1 HMAC algorithm. @n
42  *
43  *  For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/hashing.htm">Hashing</a>.
44  *
45  *      @see    IHmac
46  *      @see    Md5Hmac
47  *      @see    Sha2Hmac
48  */
49 class _OSP_EXPORT_ Sha1Hmac
50         : public virtual IHmac
51         , public Tizen::Base::Object
52 {
53
54 public:
55         /**
56          *      This is the default constructor for this class.
57          *
58          * @since               2.0
59          */
60         Sha1Hmac(void);
61
62         /**
63          * This destructor overrides Tizen::Base::Object::~Object().
64          *
65          * @since               2.0
66          */
67         virtual ~Sha1Hmac(void);
68
69         /**
70          *      Sets the HMAC algorithm. @n
71          *      The %SetAlgorithm() method is not supported by this class. Do not call this method.
72          *      If this method is called, it returns @c E_UNSUPPORTED_ALGORITHM.
73          *
74          *      @since          2.0
75          *
76          *      @return         An error code
77          *      @param[in]      algorithm                               The name of the HMAC algorithm @n
78          *                                                                              For example, "HMACSHA2/224", "HMACSHA2/256", "HMACSHA2/384", or "HMACSHA2/512".
79          *      @exception      E_SUCCESS                               The method is successful.
80          *      @exception      E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
81          *      @remarks        Do not call this method. It is not supported.
82          */
83         virtual result SetAlgorithm(const Tizen::Base::String& algorithm);
84
85         /**
86          *      Sets the secret key.
87          *
88          *      @since          2.0
89          *
90          *      @return         An error code
91          *      @param[in]      key                                             An instance of ISecretKey
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 SetKey(const Tizen::Security::ISecretKey& key);
97
98         /**
99          *      Gets HMAC with the given input.
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.
112          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
113          */
114         virtual Tizen::Base::ByteBuffer* GetHmacN(const Tizen::Base::ByteBuffer& input) const;
115
116         /**
117          *      Initializes a multiple-part HMAC operation.
118          *
119          *      @since          2.0
120          *
121          *      @return         An error code
122          *      @exception      E_SUCCESS                               The method is successful.
123          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
124          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
125          *      @exception      E_SYSTEM                                A system error has occurred. @n
126          *                                                                              The method has failed to operate with the OpenSSL library.
127          */
128         virtual result Initialize(void);
129
130         /**
131          *      Updates a multiple-part HMAC operation while processing another data part.
132          *
133          *      @since          2.0
134          *
135          *      @return         An error code
136          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
137          *      @exception      E_SUCCESS                               The method is successful.
138          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
139          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
140          *      @exception      E_SYSTEM                                A system error has occurred. @n
141          *                                                                              The method has failed to operate with the OpenSSL library, or
142          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
143          */
144         virtual result Update(const Tizen::Base::ByteBuffer& input);
145
146         /**
147          *      Finalizes a multiple-part HMAC operation.
148          *
149          *      @since          2.0
150          *
151          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
152          *                              else @c null if an error occurs
153          *      @exception      E_SUCCESS                               The method is successful.
154          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
155          *      @exception      E_SYSTEM                                A system error has occurred. @n
156          *                                                                              The method has failed to operate with the OpenSSL library, or
157          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
158          *      @remarks    The specific error code can be accessed using the GetLastResult() method.
159          */
160         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
161
162 private:
163
164         //
165         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
166         //
167         // @since 2.0
168         //
169         Sha1Hmac(const Sha1Hmac& rhs);
170
171         //
172         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
173         //
174         // @since 2.0
175         //
176         Sha1Hmac& operator =(const Sha1Hmac& rhs);
177
178 private:
179         hmac_ctx_st* __pSha1HmacCtx;
180         Tizen::Base::ByteBuffer __keyBytes;
181
182         class _Sha1HmacImpl* __pSha1HmacImpl;
183         friend class _Sha1HmacImpl;
184
185 }; //Sha1Hmac
186
187 } } } //Tizen::Security::Crypto
188
189 #endif //_FSEC_CRYPTO_SHA1_HMAC_H_