Fix internal tests
[platform/core/security/cert-svc.git] / vcore / vcore / SignatureData.cpp
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 #include <vcore/SignatureData.h>
23
24 #include <dpl/log/log.h>
25
26 namespace ValidationCore {
27
28 SignatureData::SignatureData()
29   : m_signatureNumber(-1)
30   , m_certificateSorted(false)
31 {}
32
33 SignatureData::SignatureData(const std::string &fileName, int fileNumber)
34   : m_signatureNumber(fileNumber)
35   , m_fileName(fileName)
36   , m_certificateSorted(false)
37 {}
38
39 SignatureData::~SignatureData()
40 {}
41
42 const ReferenceSet& SignatureData::getReferenceSet() const
43 {
44     return m_referenceSet;
45 }
46
47 void SignatureData::setReference(const ReferenceSet &referenceSet)
48 {
49     m_referenceSet = referenceSet;
50 }
51
52 CertificateList SignatureData::getCertList() const
53 {
54     return m_certList;
55 }
56
57 void SignatureData::setSortedCertificateList(const CertificateList &list)
58 {
59     m_certList = list;
60     m_certificateSorted = true;
61 }
62
63 bool SignatureData::isAuthorSignature() const
64 {
65     return m_signatureNumber == -1;
66 }
67
68 std::string SignatureData::getSignatureFileName() const
69 {
70     return m_fileName;
71 }
72
73 int SignatureData::getSignatureNumber() const
74 {
75     return m_signatureNumber;
76 }
77
78 std::string SignatureData::getRoleURI() const
79 {
80     return m_roleURI;
81 }
82
83 std::string SignatureData::getProfileURI() const
84 {
85     return m_profileURI;
86 }
87
88 bool SignatureData::containObjectReference(const std::string &ref) const
89 {
90     std::string rName = "#";
91     rName += ref;
92     return m_referenceSet.end() != m_referenceSet.find(rName);
93 }
94
95 ObjectList SignatureData::getObjectList() const
96 {
97     return m_objectList;
98 }
99
100 void SignatureData::setStorageType(const CertStoreId::Set &storeIdSet)
101 {
102     m_storeIdSet = storeIdSet;
103 }
104
105 const CertStoreId::Set& SignatureData::getStorageType() const
106 {
107     return m_storeIdSet;
108 }
109
110 CertStoreId::Type SignatureData::getVisibilityLevel() const
111 {
112     if (!m_storeIdSet.isContainsVis()) {
113         LogWarning("Visibility level was broken.");
114         return 0;
115     }
116
117     if (m_storeIdSet.contains(CertStoreId::VIS_PLATFORM))
118         return CertStoreId::VIS_PLATFORM;
119     else if (m_storeIdSet.contains(CertStoreId::VIS_PARTNER_MANUFACTURER))
120         return CertStoreId::VIS_PLATFORM;
121     else if (m_storeIdSet.contains(CertStoreId::VIS_PARTNER_OPERATOR))
122         return CertStoreId::VIS_PLATFORM;
123     else if (m_storeIdSet.contains(CertStoreId::VIS_PARTNER))
124         return CertStoreId::VIS_PARTNER;
125     else
126         return CertStoreId::VIS_PUBLIC;
127 }
128
129 const SignatureData::IMEIList& SignatureData::getIMEIList() const
130 {
131     return m_imeiList;
132 }
133
134 const SignatureData::MEIDList& SignatureData::getMEIDList() const
135 {
136     return m_meidList;
137 }
138
139 CertificatePtr SignatureData::getEndEntityCertificatePtr() const
140 {
141     if (m_certificateSorted)
142         return m_certList.front();
143
144     return CertificatePtr();
145 }
146
147 CertificatePtr SignatureData::getRootCaCertificatePtr() const
148 {
149     if (m_certificateSorted)
150         return m_certList.back();
151
152     return CertificatePtr();
153 }
154
155 } // ValidationCore