sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FSecSecretKeyGenerator.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                        FSecSecretKeyGenerator.h
20  * @brief               This is the header file for the %SecretKeyGenerator class.
21  *
22  * This header file contains the declarations of the %SecretKeyGenerator class.
23  */
24 #ifndef _FSEC_SECRET_KEY_GENERATOR_H_
25 #define _FSEC_SECRET_KEY_GENERATOR_H_
26
27 #include <FSecISecretKeyGenerator.h>
28 #include <FSecISecureRandom.h>
29 #include <FSecISecretKey.h>
30
31
32 namespace Tizen { namespace Security
33 {
34
35 /**
36  *      @class          SecretKeyGenerator
37  *      @brief          This class is used for generating a secret (symmetric) key.
38  *
39  *      @since       2.0
40  *
41  *  The %SecretKeyGenerator class generates a secret key, which is used in symmetric ciphers. The generated secret key is based on an encryption algorithm. @n
42  *
43  *      For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/key_mgmt_and_csprng.htm">Key Management and CSPRNG</a>.
44  *
45  *      @see ISecretKeyGenerator
46  */
47 class _OSP_EXPORT_ SecretKeyGenerator
48         : public virtual ISecretKeyGenerator
49         , public Tizen::Base::Object
50 {
51
52 public:
53         /**
54          * The object is not fully constructed after this constructor is called. For full construction, @n
55          * the Construct() method must be called right after calling this constructor.
56          *
57          * @since       2.0
58          */
59         SecretKeyGenerator(void);
60
61         /**
62          * This destructor overrides Tizen::Base::Object::~Object().
63          *
64          * @since       2.0
65          */
66         virtual ~SecretKeyGenerator(void);
67
68         /**
69          *      Constructs and initializes this instance of %SecretKeyGenerator with the specified key.
70          *
71          *      @since           2.0
72          *
73          *      @return         An error code
74          *      @param[in]      keyBytes                                The key of type Tizen::Base::ByteBuffer
75          *      @exception      E_SUCCESS                               The method is successful.
76          *      @exception      E_INVALID_ARG                   The specified @c keyBytes is invalid or an empty Tizen::Base::ByteBuffer.
77          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
78          */
79         result Construct(const Tizen::Base::ByteBuffer& keyBytes);
80
81         /**
82          *      Constructs and initializes this instance of %SecretKeyGenerator for the specified algorithm.
83          *
84          *      @since           2.0
85          *
86          *      @return         An error code
87          *      @param[in]      algorithm                               The name of the secure random generator algorithm @n
88          *                                                                                      For example, "AES","DES" or "3DES".
89          *      @exception      E_SUCCESS                               The method is successful.
90          *      @exception      E_INVALID_ARG                   The specified @c algorithm is invalid or an empty string.
91          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
92          */
93         result Construct(const Tizen::Base::String& algorithm);
94
95         /**
96          *      Constructs and initializes this instance of %SecretKeyGenerator with the specified key size. @n
97          *      The default algorithm is Advanced Encryption Standard (AES).
98          *
99          *      @since           2.0
100          *
101          *      @return         An error code
102          *      @param[in]      keySize                                 The key size
103          *      @exception      E_SUCCESS                               The method is successful.
104          *      @exception      E_INVALID_ARG                   The specified @c keySize is @c 0 or negative.
105          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
106          */
107         result Construct(int keySize);
108
109         /**
110          *      Generates a new secret key.
111          *
112          *      @since           2.0
113          *
114          *      @return         A pointer to the ISecretKey interface, @n
115          *                                      else @c null if it fails to generate a secret key
116          *      @exception      E_SUCCESS                               The method is successful.
117          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
118          *      @exception      E_SYSTEM                A system error has occurred.
119          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
120          */
121         virtual Tizen::Security::ISecretKey* GenerateKeyN(void);
122
123 private:
124
125         //
126         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
127         //
128         // @since 2.0
129         //
130         SecretKeyGenerator(const SecretKeyGenerator& rhs);
131
132         //
133         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
134         //
135         // @since 2.0
136         //
137         SecretKeyGenerator& operator =(const SecretKeyGenerator& rhs);
138
139 private:
140         Tizen::Base::String __algorithm;
141         int __keyGenSize;
142         Tizen::Security::ISecureRandom* __pRandom;
143         Tizen::Base::ByteBuffer __keyBytes;
144
145         class _SecretKeyGeneratorImpl* __pSecretKeyGeneratorImpl;
146         friend class _SecretKeyGeneratorImpl;
147
148 }; //SecretKeyGenerator
149
150 } } //Tizen::Security
151
152 #endif // _FSEC_SECRET_KEY_GENERATOR_H_