2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef _WRT_ENGINE_SRC_VALIDATION_CORE_CERTIFICATECOLLECTION_H_
17 #define _WRT_ENGINE_SRC_VALIDATION_CORE_CERTIFICATECOLLECTION_H_
22 #include <dpl/exception.h>
24 #include <vcore/Certificate.h>
26 namespace ValidationCore {
28 * This class is used to store Certificate Chain.
29 * It could serialize chain to std::string in base64 form.
30 * It could read chain written in base64 form.
31 * It could check if collection creates certificate chain.
34 class CertificateCollection
40 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
41 DECLARE_EXCEPTION_TYPE(Base, WrongUsage)
44 CertificateCollection();
46 typedef CertificateList::const_iterator const_iterator;
49 * Remove all certificates from collection.
54 * In current implemenation this function MUST success.
56 * This function will add new certificate to collection.
57 * This function DOES NOT clean collection.
59 void load(const CertificateList &certList);
62 * This function will return false if base64 string is broken
63 * (is not encoded in base64 format) or one from certificate
64 * is broken (is not encoded in der format).
66 * This function will add new certificate to collection.
67 * This function DOES NOT clean collection.
69 bool load(const std::string &base64);
72 * This function will return all certificates from
73 * collection encoded in base64 format.
75 std::string toBase64String() const;
78 * This will return all certificate from collection.
80 CertificateList getCertificateList() const;
83 * This function will return true if certificates
84 * in in this structure were sorted and create
87 * Note: You MUST sort certificates first.
92 * This function will return true if all certificate are
93 * able to create certificate chain.
95 * This function will sort certificates if collection
98 * Note: This function will make all iterators invalid.
103 * This function will return Certificate chain.
105 * Note: You MUST sort certificates first and
106 * check if certificates creates proper chain.
108 CertificateList getChain() const;
111 * It returns size of certificate collection.
113 inline size_t size() const
115 return m_certList.size();
119 * Return true if collection is empty.
121 inline bool empty() const
123 return m_certList.empty();
127 * This will return end iterator to internal collection.
129 * Note: this iterator will lose validity if you call non const
130 * method on CertificateCollection class.
132 inline const_iterator begin() const
134 return m_certList.begin();
138 * This will return end iterator to internal collection.
140 * Note: this iterator will lose validity if you call non const
141 * method on CertificateCollection class.
143 inline const_iterator end() const
145 return m_certList.end();
149 * This function will return the last certificate from collection.
151 * Note: There is no point to call this function if certificate
152 * collection is not sorted!
154 inline CertificatePtr back() const
156 return m_certList.back();
160 void sortCollection(void);
162 enum CollectionStatus
164 // Certificate collection are not sorted in any way
166 // Certificate collection creates certificate chain
168 // Cerfificate collection is not able to create certificate chain
169 COLLECTION_CHAIN_BROKEN,
172 CollectionStatus m_collectionStatus;
173 CertificateList m_certList;
176 typedef std::list<CertificateCollection> CertificateCollectionList;
177 } // namespace ValidationCore
179 #endif // _WRT_ENGINE_SRC_VALIDATION_CORE_CERTIFICATECHAIN_H_