c218c60dc96c0988d23da860f04d7f046278e2e7
[platform/framework/native/appfw.git] / inc / FSecPkcsPkcs08PrivateKeyInfo.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2013 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                FSecPkcsPkcs08PrivateKeyInfo.h
20  * @brief               This is the header file for the %Pkcs08PrivateKeyInfo class.
21  *
22  * This header file contains the declarations of the %Pkcs08PrivateKeyInfo class.
23  */
24
25 #ifndef _FSEC_PKCS_PKCS_08_PRIVATE_KEY_INFO_H_
26 #define _FSEC_PKCS_PKCS_08_PRIVATE_KEY_INFO_H_
27
28 #include <FBaseByteBuffer.h>
29 #include <FSecPkcsAlgorithmIdentifier.h>
30 #include <FSecPkcsPkcs08Attribute.h>
31 #include <FSecPkcsPkcs08AttributeValue.h>
32
33
34 namespace Tizen { namespace Security { namespace Pkcs
35 {
36
37 /**
38  * @class               Pkcs08PrivateKeyInfo
39  * @brief               This class implements the functionalities specified by the Pkcs08 PrivateKeyInfo class.
40  *                              This class represents the structure of Pkcs08 Private Key Info.
41  *
42  *                              It is defined in ASN.1 as:
43  *
44  *                              PrivateKeyInfo ::= SEQUENCE {
45  *                              version Version,
46  *                              privateKeyAlgorithm AlgorithmIdentifier {{PrivateKeyAlgorithms}},
47  *                              privateKey PrivateKey,
48  *                              attributes [0] Attributes OPTIONAL }
49  * @since               2.1
50  *
51  */
52
53 class _OSP_EXPORT_ Pkcs08PrivateKeyInfo
54         : public Tizen::Base::Object
55 {
56
57 public:
58         /**
59          * The object is not fully constructed after this constructor is called. @n
60          * For full construction, the Construct() method must be called right after calling this constructor.
61          *
62          * @since               2.1
63          */
64         Pkcs08PrivateKeyInfo(void);
65
66         /**
67          * This destructor overrides Tizen::Base::Object::~Object().
68          *
69          * @since               2.1
70          */
71         virtual ~Pkcs08PrivateKeyInfo(void);
72
73         /**
74          * Initializes this instance of %Pkcs08PrivateKeyInfo with the encoded byte buffer which contain  @n
75          * pkcs08 private key info structure(PrivateKeyInfo) in ASN.1 DER format. @n
76          * It parses this encoded buffer and extracts the appropiate values of private key, its algorithm id and attributes.
77          *
78          * @since               2.1
79          *
80          * @return              An error code
81          * @param[in]   encodedData                                     The instance of Bytebuffer, containing DER encoded PrivateKeyInfo structure.
82          * @exception   E_SUCCESS                                               The method is successful.
83          * @exception   E_INVALID_ARG                           The specified input parameter is invalid.
84          */
85         result Construct(const Tizen::Base::ByteBuffer& encodedData);
86
87         /**
88          * Initializes the %Pkcs08PrivateKeyInfo with supplied input parameters values.
89          *
90          * @since               2.1
91          *
92          * @return              An error code.
93          * @param[in]   keyAlgorithmId                  An instance of AlgorithIdentifier, holding algorithm identifier of private key algorithm.
94          * @param[in]   privateKey                                      An instance of ByteBuffer holding privatekey.
95          * @exception   E_SUCCESS                                               The method is successful.
96          * @exception   E_INVALID_ARG                           The specified input parameter is invalid.
97          */
98         result Construct(const AlgorithmIdentifier& keyAlgorithmId, const Tizen::Base::ByteBuffer& privateKey);
99
100         /**
101          * This function will provide the implementation of GetVersion API to get the private key syntax version number of PrivateKeyInfo object @n
102          * that is used for storing private key and its related information and default value of this version is 0.
103          *
104          * @since               2.1
105          *
106          * @return              An integer valuse contains the version.
107          *
108          */
109         int GetVersion(void) const;
110
111         /**
112          * Gets the reference to AlgorithmIdentifier which identifies the secret key algorithm.
113          *
114          * @since               2.1
115          *
116          * @return              A reference to AlgorithmIdentifier Contains the algorithm identifier of Pkcs08PrivateKeyInfo object.
117          * @remarks             The specific error code can be accessed using the GetLastResult() method.
118          */
119         const AlgorithmIdentifier& GetPrivateKeyAlgorithm(void) const;
120
121         /**
122          * This function will provide the implementation of GetPrivateKeyN API to get the reference to ByteBuffer which contains
123          * the private key in binary format.
124          *
125          * @since               2.1
126          *
127          * @return              A reference to ByteBuffer Contains the private key of Pkcs08PrivateKeyInfo object.
128          * @remarks             The specific error code can be accessed using the GetLastResult() method.
129          */
130         const Tizen::Base::ByteBuffer& GetPrivateKey(void) const;
131
132         /**
133          * This API will provide the implementation of GetAttributes API to get the Attributes of type Pkcs08Attribute which are extended @n
134          * information of private key in context.
135          *
136          * @since               2.1
137          *
138          * @return              Reference to array list, contains the list of attributes of type Pkcs08Attribute.
139          */
140         const Tizen::Base::Collection::ArrayList& GetAttributes(void) const;
141
142         /**
143          * This function adds Attributes in private key info i.e. extended information of private key in context.
144          *
145          * @since               2.1
146          *
147          * @return              An error code
148          * @param[in]   attributes                                      An instance of Pkcs08Attribute class..
149          */
150         result AddAttribute(const Pkcs08Attribute& attributes);
151
152         /**
153          * This function remove Attribute in private key info i.e. extended information of private key in context.
154          *
155          * @since               2.1
156          *
157          * @return              An error code
158          * @param[in]   attributes                                      An instance of Pkcs08Attribute class.
159          */
160         result RemoveAttribute(const Pkcs08Attribute& attributes);      
161         
162         /**
163          * Gets the DER encoded Pkcs08PrivateKeyInfo structure.
164          *
165          * @since               2.1
166          *
167          * @return              Pointer to ByteBuffer Contains the DER encoded private key info.
168          * @exception   E_SUCCESS                                               The method is successful.
169          * @exception   E_SYSTEM                                                The method cannot proceed due to a severe system error.
170          * @remarks             The specific error code can be accessed using the GetLastResult() method.
171          */
172         Tizen::Base::ByteBuffer* GetEncodedDataN(void) const;
173
174 private:
175         // This copy constructor is intentionally declared as private to prohibit @n
176         // copying of objects by users.
177         //
178         // @since               2.1
179         Pkcs08PrivateKeyInfo(const Pkcs08PrivateKeyInfo& rhs);
180
181         // The implementation of this copy assignment operator is intentionally blank and @n
182         // declared as private to prohibit copying of objects.
183         //
184         // @since               2.1
185         Pkcs08PrivateKeyInfo& operator =(const Pkcs08PrivateKeyInfo& rhs);
186
187 private:
188         class _Pkcs08PrivateKeyInfoImpl* __pPkcs08PrivateKeyInfoImpl;
189         friend class _Pkcs08PrivateKeyInfoImpl;
190
191 }; //Pkcs08PrivateKeyInfo
192
193 }}} // Tizen::Security::Pkcs
194
195 #endif // _FSEC_PKCS_PKCS_08_PRIVATE_KEY_INFO_H_