a8a84fa1a443de7023643433f8b9e8d92b80882d
[platform/core/security/cert-svc.git] / vcore / src / 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.contains(CertStoreId::VIS_PLATFORM))
113         return CertStoreId::VIS_PLATFORM;
114     else if (m_storeIdSet.contains(CertStoreId::VIS_PARTNER_MANUFACTURER))
115         return CertStoreId::VIS_PLATFORM;
116     else if (m_storeIdSet.contains(CertStoreId::VIS_PARTNER_OPERATOR))
117         return CertStoreId::VIS_PLATFORM;
118     else if (m_storeIdSet.contains(CertStoreId::VIS_PARTNER))
119         return CertStoreId::VIS_PARTNER;
120     else if (m_storeIdSet.contains(CertStoreId::VIS_PUBLIC))
121         return CertStoreId::VIS_PUBLIC;
122     else {
123         LogWarning("Visibility level was broken.");
124         return 0;
125     }
126 }
127
128 const SignatureData::IMEIList& SignatureData::getIMEIList() const
129 {
130     return m_imeiList;
131 }
132
133 const SignatureData::MEIDList& SignatureData::getMEIDList() const
134 {
135     return m_meidList;
136 }
137
138 CertificatePtr SignatureData::getEndEntityCertificatePtr() const
139 {
140     if (m_certificateSorted)
141         return m_certList.front();
142
143     return CertificatePtr();
144 }
145
146 CertificatePtr SignatureData::getRootCaCertificatePtr() const
147 {
148     if (m_certificateSorted)
149         return m_certList.back();
150
151     return CertificatePtr();
152 }
153
154 } // ValidationCore