Add to retry to read DUID.
[platform/framework/native/appfw.git] / inc / FSecSecretKeyGenerator.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                        FSecSecretKeyGenerator.h
19  * @brief               This is the header file for the %SecretKeyGenerator class.
20  *
21  * This header file contains the declarations of the %SecretKeyGenerator class.
22  */
23 #ifndef _FSEC_SECRET_KEY_GENERATOR_H_
24 #define _FSEC_SECRET_KEY_GENERATOR_H_
25
26 #include <FSecISecretKeyGenerator.h>
27 #include <FSecISecureRandom.h>
28 #include <FSecISecretKey.h>
29
30
31 namespace Tizen { namespace Security
32 {
33
34 /**
35  *      @class          SecretKeyGenerator
36  *      @brief          This class is used for generating a secret (symmetric) key.
37  *
38  *      @since       2.0
39  *
40  *  The %SecretKeyGenerator class generates a secret key, which is used in symmetric ciphers. The generated secret key is based on an encryption algorithm. @n
41  *
42  *      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>.
43  *
44  *      @see ISecretKeyGenerator
45  */
46 class _OSP_EXPORT_ SecretKeyGenerator
47         : public virtual ISecretKeyGenerator
48         , public Tizen::Base::Object
49 {
50
51 public:
52         /**
53          * The object is not fully constructed after this constructor is called. For full construction, @n
54          * the Construct() method must be called right after calling this constructor.
55          *
56          * @since       2.0
57          */
58         SecretKeyGenerator(void);
59
60         /**
61          * This destructor overrides Tizen::Base::Object::~Object().
62          *
63          * @since       2.0
64          */
65         virtual ~SecretKeyGenerator(void);
66
67         /**
68          *      Constructs and initializes this instance of %SecretKeyGenerator with the specified key.
69          *
70          *      @since           2.0
71          *
72          *      @return         An error code
73          *      @param[in]      keyBytes                                The key of type Tizen::Base::ByteBuffer
74          *      @exception      E_SUCCESS                               The method is successful.
75          *      @exception      E_INVALID_ARG                   The specified @c keyBytes is invalid or an empty Tizen::Base::ByteBuffer.
76          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
77          */
78         result Construct(const Tizen::Base::ByteBuffer& keyBytes);
79
80         /**
81          *      Constructs and initializes this instance of %SecretKeyGenerator for the specified @c algorithm.
82          *
83          *      @since           2.0
84          *
85          *      @return         An error code
86          *      @param[in]      algorithm                               The name of the secure random generator algorithm @n
87          *                                                                                      For example, "AES","DES", or "3DES".
88          *      @exception      E_SUCCESS                               The method is successful.
89          *      @exception      E_INVALID_ARG                   The specified @c algorithm is invalid or an empty string.
90          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
91          */
92         result Construct(const Tizen::Base::String& algorithm);
93
94         /**
95          *      Constructs and initializes this instance of %SecretKeyGenerator with the specified key size. @n
96          *      The default algorithm is Advanced Encryption Standard (AES).
97          *
98          *      @since           2.0
99          *
100          *      @return         An error code
101          *      @param[in]      keySize                                 The key size
102          *      @exception      E_SUCCESS                               The method is successful.
103          *      @exception      E_INVALID_ARG                   The specified @c keySize is @c 0 or negative.
104          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
105          */
106         result Construct(int keySize);
107
108         /**
109          *      Generates a new secret key.
110          *
111          *      @since           2.0
112          *
113          *      @return         A pointer to the ISecretKey interface, @n
114          *                                      else @c null if it fails to generate a secret key
115          *      @exception      E_SUCCESS                               The method is successful.
116          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
117          *      @exception      E_SYSTEM                A system error has occurred.
118          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
119          */
120         virtual Tizen::Security::ISecretKey* GenerateKeyN(void);
121
122 private:
123
124         //
125         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
126         //
127         // @since 2.0
128         //
129         SecretKeyGenerator(const SecretKeyGenerator& rhs);
130
131         //
132         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
133         //
134         // @since 2.0
135         //
136         SecretKeyGenerator& operator =(const SecretKeyGenerator& rhs);
137
138 private:
139         Tizen::Base::String __algorithm;
140         int __keyGenSize;
141         Tizen::Security::ISecureRandom* __pRandom;
142         Tizen::Base::ByteBuffer __keyBytes;
143
144         class _SecretKeyGeneratorImpl* __pSecretKeyGeneratorImpl;
145         friend class _SecretKeyGeneratorImpl;
146
147 }; //SecretKeyGenerator
148
149 } } //Tizen::Security
150
151 #endif // _FSEC_SECRET_KEY_GENERATOR_H_