Update reviewed Tizen::Io doxygen
[platform/framework/native/appfw.git] / inc / FSecRsaKeyConverter.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                        FSecRsaKeyConverter.h
20  * @brief               This is the header file for the %RsaKeyConverter class.
21  *
22  * This header file contains the declarations of the %RsaKeyConverter class.
23  */
24
25 #ifndef _FSEC_RSA_KEY_CONVERTER_H_
26 #define _FSEC_RSA_KEY_CONVERTER_H_
27
28 #include <FSecIPublicKey.h>
29 #include <FSecIPrivateKey.h>
30
31 namespace Tizen { namespace Security
32 {
33
34 /**
35  * @enum    RsaKeyFormat
36  *
37  * Defines the types of rsa key format.
38  *
39  * @since               2.1
40  */
41 enum RsaKeyFormat
42 {
43         RSA_KEY_FORMAT_PKCS01_PRIVATE_KEY = 0,     /**< The rsa key format is PKCS1 private key */
44         RSA_KEY_FORMAT_PKCS01_PUBLIC_KEY = 1,      /**< The rsa key format is PKCS1 public key */
45         RSA_KEY_FORMAT_PKCS08_PRIVATE_KEY = 2,     /**< The rsa key format is PKCS8 private key */
46         RSA_KEY_FORMAT_X509_PUBLIC_KEY = 3,      /**< The rsa key format is X509 public key */
47         RSA_KEY_FORMAT_UNKNOWN = 0xffffffff       /**< The rsa key format is unknown */
48 }; //RsaKeyFormat;
49
50 /**
51  *  @class              RsaKeyConverter
52  *  @brief              This class provides support for converting the RSA public/private key in multiple key formats and multiple encoding formats.
53  *
54  *  @since      2.1
55  *
56  *  The %RsaKeyConverter class provides support for converting the RSA public/private key in multiple key formats and multiple encoding formats. @n
57  *                              Supported RSA key formats are PKCS1/PKCS8/X509. @n
58  *                              Supported encoding formats are DER/PEM.
59  */
60
61 class _OSP_EXPORT_ RsaKeyConverter
62 {
63
64 public:
65         /**
66          *      Generates a RSA encoded private key in the passed input RSA key format. @n
67          *      If the input private key is in PEM encoded format, then the output RSA private key will be PEM encoded; if it is in DER encoded format,
68          *      then the output RSA private key will be DER encoded.
69          *
70          *      @since          2.1
71          *
72          *      @return         A pointer to the encoded Tizen::Base::ByteBuffer instance, @n
73          *                          else @c null if the method fails to convert the private key in the passed input format
74          *      @param[in]      format                          An enum value that contains the RSA private key format @n
75          *                                                                      Valid values for the supported output RSA private key formats are only @c RSA_KEY_FORMAT_PKCS01_PRIVATE_KEY and @c RSA_KEY_FORMAT_PKCS08_PRIVATE_KEY.
76          *      @param[in]      key                                     An instance of IPrivateKey
77          *      @exception      E_SUCCESS                                       The method is successful.
78          *      @exception      E_INVALID_ARG           A specified input parameter is invalid.
79          *  @remarks    The specific error code can be accessed using the GetLastResult() method.
80          */
81         static Tizen::Base::ByteBuffer* ConvertPrivateKeyFormatN(RsaKeyFormat format, const IPrivateKey& key);
82
83         /**
84          *      Generates a RSA encoded public key in the passed input RSA key format. @n
85          *      If the input public key is in PEM encoded format, then the output RSA public key will be PEM encoded; if it is in DER encoded format,
86          *      then the output RSA public key will be DER encoded.
87          *
88          *      @since          2.1
89          *
90          *      @return         A pointer to the encoded Tizen::Base::ByteBuffer instance, @n
91          *                              else @c null if the method fails to convert the public key in the passed input format
92          *      @param[in]      format                          An enum value that contains the RSA public key format @n
93          *                                                                      Valid values for the supported output RSA public key formats are only @c RSA_KEY_FORMAT_PKCS01_PUBLIC_KEY and @c RSA_KEY_FORMAT_X509_PUBLIC_KEY.
94          *      @param[in]      key                                     An instance of IPublicKey
95          *      @exception      E_SUCCESS                                       The method is successful.
96          *      @exception      E_INVALID_ARG           A specified input parameter is invalid.
97          *      @remarks    The specific error code can be accessed using the GetLastResult() method.
98          */
99         static Tizen::Base::ByteBuffer* ConvertPublicKeyFormatN(RsaKeyFormat format, const IPublicKey& key);
100
101         /**
102          *      Converts a DER encoded RSA key to the PEM encoded format.
103          *
104          *      @since          2.1
105          *
106          *      @return         A pointer to the PEM encoded Tizen::Base::ByteBuffer instance, @n
107          *                              else @c null if the method fails to convert the key in the PEM encoded format
108          *      @param[in]      format                          An enum value that contains the RSA key format of the input key
109          *      @param[in]      key                                     An instance of IKey
110          *      @exception      E_SUCCESS                                       The method is successful.
111          *      @exception      E_INVALID_ARG           A specified input parameter is invalid.
112          *      @remarks    The specific error code can be accessed using the GetLastResult() method.
113          */
114         static Tizen::Base::ByteBuffer* ConvertDerToPemN(RsaKeyFormat format, const IKey& key);
115
116         /**
117          *      Converts a PEM encoded RSA key to the DER encoded format.
118          *
119          *      @since          2.1
120          *
121          *      @return         A pointer to the DER encoded Tizen::Base::ByteBuffer instance, @n
122          *                                  else @c null if the method fails to convert the key in the DER encoded format
123          *      @param[in]      format                          An enum value that contains the RSA key format of the input key
124          *      @param[in]      key                                     An instance of IKey
125          *      @exception      E_SUCCESS                                       The method is successful.
126          *      @exception      E_INVALID_ARG           A specified input parameter is invalid.
127          *  @remarks    The specific error code can be accessed using the GetLastResult() method.
128          */
129         static Tizen::Base::ByteBuffer* ConvertPemToDerN(RsaKeyFormat format, const IKey& key);
130
131 private:
132         //
133         // This default constructor is intentionally declared as private because this class cannot be constructed.
134         //
135         // @since       2.1
136         //
137         RsaKeyConverter(void);
138
139         //
140         // This destructor is intentionally declared as private because this class cannot be constructed.
141         //
142         // @since       2.1
143         //
144         ~RsaKeyConverter(void);
145
146         //
147         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
148         //
149         // @since 2.1
150         //
151         RsaKeyConverter(const RsaKeyConverter& rhs);
152
153         //
154         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
155         //
156         // @since 2.1
157         //
158         RsaKeyConverter& operator =(const RsaKeyConverter& rhs);
159
160 private:
161         class _RsaKeyConverterImpl* __pRsaKeyConverterImpl;
162         friend class _RsaKeyConverterImpl;
163
164 };     //RsaKeyConverter
165
166 } } //Tizen::Security
167
168 #endif // _FSEC_RSA_KEY_CONVERTER_H_