Coding style applied according to style checker
[platform/core/security/key-manager.git] / src / manager / common / data-type.h
1 /*
2  *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file       data-type.h
18  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
19  * @version    1.0
20  */
21
22 #pragma once
23
24 #include <ckm/ckm-type.h>
25 #include <dpl/exception.h>
26 #include <symbol-visibility.h>
27
28 namespace CKM {
29
30 class COMMON_API DataType {
31 public:
32         class Exception {
33         public:
34                 DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
35                 DECLARE_EXCEPTION_TYPE(Base, OutOfRange)
36         };
37
38         enum Type {
39                 KEY_RSA_PUBLIC,
40                 KEY_RSA_PRIVATE,
41                 KEY_ECDSA_PUBLIC,
42                 KEY_ECDSA_PRIVATE,
43                 KEY_DSA_PUBLIC,
44                 KEY_DSA_PRIVATE,
45                 KEY_AES,
46                 CERTIFICATE,
47                 BINARY_DATA,
48
49                 CHAIN_CERT_0,
50                 CHAIN_CERT_1,
51                 CHAIN_CERT_2,
52                 CHAIN_CERT_3,
53                 CHAIN_CERT_4,
54                 CHAIN_CERT_5,
55                 CHAIN_CERT_6,
56                 CHAIN_CERT_7,
57                 CHAIN_CERT_8,
58                 CHAIN_CERT_9,
59                 CHAIN_CERT_10,
60                 CHAIN_CERT_11,
61                 CHAIN_CERT_12,
62                 CHAIN_CERT_13,
63                 CHAIN_CERT_14,
64                 CHAIN_CERT_15,
65
66                 // Special types to support database,
67                 DB_KEY_FIRST = KEY_RSA_PUBLIC,
68                 DB_KEY_LAST  = KEY_AES,
69                 DB_CHAIN_FIRST = CHAIN_CERT_0,
70                 DB_CHAIN_LAST = CHAIN_CERT_15,
71                 DB_FIRST = KEY_RSA_PUBLIC,
72                 DB_LAST  = CHAIN_CERT_15,
73         };
74
75         DataType();
76         DataType(Type data);
77         explicit DataType(int data);
78         explicit DataType(KeyType key);
79         explicit DataType(AlgoType algorithmType);
80         DataType(const DataType &) = default;
81         DataType &operator=(const DataType &) = default;
82
83         operator int () const;
84         operator KeyType() const;
85         bool operator==(const DataType &second) const;
86
87         bool isKey() const;
88         bool isSKey() const;
89         bool isChainCert() const;
90         bool isKeyPrivate() const;
91         bool isKeyPublic() const;
92         bool isCertificate() const;
93         bool isBinaryData() const;
94
95         static bool isInRange(int data);
96         static DataType getChainDatatype(unsigned int index);
97
98         // it's not virtual for a reason!
99         ~DataType() {}
100
101 private:
102         Type m_dataType;
103 };
104
105 } // namespace CKM