sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FSecCryptoSha2Hash.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           FSecCryptoSha2Hash.h
20  *      @brief          This is the header file for the %Sha2Hash class.
21  *
22  *      This header file contains the declarations of the %Sha2Hash class.
23  */
24 #ifndef _FSEC_CRYPTO_SHA2_HASH_H_
25 #define _FSEC_CRYPTO_SHA2_HASH_H_
26
27 #include <FSecCryptoIHash.h>
28
29 struct env_md_st;
30 struct env_md_ctx_st;
31
32 namespace Tizen { namespace Security { namespace Crypto
33 {
34
35 /**
36  *      @class  Sha2Hash
37  *      @brief  This class implements the SHA-2 hash algorithm.
38  *
39  *      @since  2.0
40  *
41  *      The %Sha2Hash class implements the SHA-2 hash 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            Tizen::Security::Crypto::IHash
46  *      @see            Tizen::Security::Crypto::Md5Hash
47  *      @see            Tizen::Security::Crypto::Sha1Hash
48  */
49 class _OSP_EXPORT_ Sha2Hash
50         : public virtual IHash
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         Sha2Hash(void);
61
62         /**
63          * This destructor overrides Tizen::Base::Object::~Object().
64          *
65          *      @since          2.0
66          */
67         virtual ~Sha2Hash(void);
68
69         /**
70          *      Sets the hash algorithm.
71          *
72          *      @since          2.0
73          *
74          *      @return         An error code
75          *      @param[in]      algorithm                               The name of the hash algorithm @n
76          *                                                                              For example, "SHA2/224", "SHA2/256", "SHA2/386", or "SHA2/512".
77          *      @exception      E_SUCCESS                               The method is successful.
78          *      @exception      E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
79          */
80         virtual result SetAlgorithm(const Tizen::Base::String& algorithm);
81
82         /**
83          *      Gets the hashes of the data (single-part).
84          *
85          *      @since          2.0
86          *
87          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
88          *                              else @c null if an error occurs
89          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
90          *      @exception      E_SUCCESS                               The method is successful.
91          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
92          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
93          *      @exception      E_SYSTEM                                A system error has occurred. @n
94          *                                                                              The method has failed to operate with the OpenSSL library, or
95          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
96          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
97          */
98         virtual Tizen::Base::ByteBuffer* GetHashN(const Tizen::Base::ByteBuffer& input) const;
99
100         /**
101          *      Initializes the multiple-part hash operation.
102          *
103          *      @since          2.0
104          *
105          *      @return         An error code
106          *      @exception      E_SUCCESS                               The method is successful.
107          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
108          *      @exception      E_SYSTEM                                A system error has occurred. @n
109          *                                                                              The method has failed to operate with the OpenSSL library.
110          */
111         virtual result Initialize(void);
112
113         /**
114          *      Updates a multiple-part hash operation while processing another data part.
115          *
116          *      @since          2.0
117          *
118          *      @return         An error code
119          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
120          *      @exception      E_SUCCESS                               The method is successful.
121          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
122          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
123          *      @exception      E_SYSTEM                                A system error has occurred. @n
124          *                                                                              The method has failed to operate with the OpenSSL library, or
125          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
126          */
127         virtual result Update(const Tizen::Base::ByteBuffer& input);
128
129         /**
130          *      Finalizes a multiple-part hash operation.
131          *
132          *      @since          2.0
133          *
134          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
135          *                              else @c null if an error occurs
136          *      @exception      E_SUCCESS                               The method is successful.
137          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
138          *      @exception      E_SYSTEM                                A system error has occurred. @n
139          *                                                                              The method has failed to operate with the OpenSSL library, or
140          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
141          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
142          */
143         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
144
145 private:
146
147         //
148         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
149         //
150         // @since 2.0
151         //
152         Sha2Hash(const Sha2Hash& rhs);
153
154         //
155         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
156         //
157         // @since 2.0
158         //
159         Sha2Hash& operator =(const Sha2Hash& rhs);
160
161 private:
162         const env_md_st* __pAlgorithm;
163         env_md_ctx_st* __pEvpMdCtx;
164
165         class _Sha2HashImpl* __pSha2HashImpl;
166         friend class _Sha2HashImpl;
167
168 }; //Sha2Hash
169
170 } } } //Tizen::Security:Crypto
171
172 #endif //_FSEC_CRYPTO_SHA2_HASH_H_