Tizen 2.1 base
[framework/web/wrt-commons.git] / modules / vcore / src / vcore / SignatureData.h
1 /*
2  * Copyright (c) 2011 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        SignatureData.cpp
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       SignatureData is used to storage data parsed from digsig file.
21  */
22 #ifndef _SIGNATUREDATA_H_
23 #define _SIGNATUREDATA_H_
24
25 #include <list>
26 #include <set>
27 #include <string>
28
29 #include <dpl/log/log.h>
30 #include <dpl/noncopyable.h>
31 #include <dpl/string.h>
32
33 #include "Certificate.h"
34 #include "CertStoreType.h"
35 #include "ValidatorCommon.h"
36
37 /* TODO this class should not depend from OCSP headers */
38 #include "OCSPCertMgrUtil.h"
39
40 namespace ValidationCore {
41 class SignatureData
42 {
43   public:
44
45     SignatureData() :
46         m_signatureNumber(-1),
47         m_certificateSorted(false)
48     {
49     }
50
51     SignatureData(std::string fileName,
52             int fileNumber) :
53         m_signatureNumber(fileNumber),
54         m_fileName(fileName),
55         m_certificateSorted(false)
56     {
57     }
58
59     virtual ~SignatureData()
60     {
61     }
62     typedef std::list<std::string> IMEIList;
63     typedef std::list<std::string> MEIDList;
64
65     const ReferenceSet& getReferenceSet() const
66     {
67         return m_referenceSet;
68     }
69
70     void setReference(const ReferenceSet &referenceSet)
71     {
72         m_referenceSet = referenceSet;
73     }
74
75     CertificateList getCertList(void) const
76     {
77         return m_certList;
78     }
79
80     void setSortedCertificateList(const CertificateList &list)
81     {
82         m_certList = list;
83         m_certificateSorted = true;
84     }
85
86     bool isAuthorSignature(void) const
87     {
88         return m_signatureNumber == -1;
89     }
90
91     std::string getSignatureFileName(void) const
92     {
93         return m_fileName;
94     }
95
96     int getSignatureNumber() const
97     {
98         return m_signatureNumber;
99     }
100
101     std::string getRoleURI() const
102     {
103         return m_roleURI;
104     }
105
106     std::string getProfileURI() const
107     {
108         return m_profileURI;
109     }
110
111     bool containObjectReference(const std::string &ref) const
112     {
113         std::string rName = "#";
114         rName += ref;
115         return m_referenceSet.end() != m_referenceSet.find(rName);
116     }
117
118     ObjectList getObjectList() const
119     {
120         return m_objectList;
121     }
122
123     void setStorageType(const CertStoreId::Set &storeIdSet)
124     {
125         m_storeIdSet = storeIdSet;
126     }
127
128     const CertStoreId::Set& getStorageType(void) const
129     {
130         return m_storeIdSet;
131     }
132
133     const IMEIList& getIMEIList() const
134     {
135         return m_imeiList;
136     }
137
138     const MEIDList& getMEIDList() const
139     {
140         return m_meidList;
141     }
142
143     CertificatePtr getEndEntityCertificatePtr() const
144     {
145         if (m_certificateSorted) {
146             return m_certList.front();
147         }
148         return CertificatePtr();
149     }
150
151     CertificatePtr getRootCaCertificatePtr() const
152     {
153         if (m_certificateSorted) {
154             return m_certList.back();
155         }
156         return CertificatePtr();
157     }
158
159     friend class SignatureReader;
160   private:
161     ReferenceSet m_referenceSet;
162     CertificateList m_certList;
163
164     //TargetRestriction
165     IMEIList m_imeiList;
166     MEIDList m_meidList;
167
168     /*
169      * This number is taken from distributor signature file name.
170      * Author signature do not contain any number on the file name.
171      * Author signature should have signature number equal to -1.
172      */
173     int m_signatureNumber;
174     std::string m_fileName;
175     std::string m_roleURI;
176     std::string m_profileURI;
177     std::string m_identifier;
178     ObjectList m_objectList;
179     CertStoreId::Set m_storeIdSet;
180     bool m_certificateSorted;
181 };
182
183 typedef std::set<SignatureData> SignatureDataSet;
184 }
185
186 #endif