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.
17 * @file CertificateCollection.h
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
22 #ifndef _VALIDATION_CORE_CERTIFICATECOLLECTION_H_
23 #define _VALIDATION_CORE_CERTIFICATECOLLECTION_H_
29 #include <vcore/exception.h>
31 #include <vcore/Certificate.h>
33 namespace ValidationCore {
35 * This class is used to store Certificate Chain.
36 * It could serialize chain to std::string in base64 form.
37 * It could read chain written in base64 form.
38 * It could check if collection creates certificate chain.
41 class CertificateCollection {
45 VCORE_DECLARE_EXCEPTION_TYPE(ValidationCore::Exception, Base);
46 VCORE_DECLARE_EXCEPTION_TYPE(Base, WrongUsage);
49 CertificateCollection();
51 typedef CertificateList::const_iterator const_iterator;
54 * Remove all certificates from collection.
59 * In current implemenation this function MUST success.
61 * This function will add new certificate to collection.
62 * This function DOES NOT clean collection.
64 void load(const CertificateList &certList);
67 * This function will return all certificates from
68 * collection encoded in base64 format.
70 std::string toBase64String() const;
73 * This will return all certificate from collection.
75 CertificateList getCertificateList() const;
78 * This function will return true if certificates
79 * in in this structure were sorted and create
82 * Note: You MUST sort certificates first.
87 * This function will return true if all certificate are
88 * able to create certificate chain.
90 * This function will sort certificates if collection
93 * Note: This function will make all iterators invalid.
98 * Precondition : cert list sorted and has more than on cert.
99 * This function add root cert in cert list to complete cert chain
101 bool completeCertificateChain();
104 * This function will return Certificate chain.
106 * First certificate on the list is EndEntity certificate.
108 * Last certificate on the list is RootCA certificate or
109 * CA certificate if RootCA is not present.
111 * Note: You MUST sort certificates first and
112 * check if certificates creates proper chain.
114 CertificateList getChain() const;
117 * It returns size of certificate collection.
122 * Return true if collection is 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 const_iterator begin() const;
135 * This will return end iterator to internal collection.
137 * Note: this iterator will lose validity if you call non const
138 * method on CertificateCollection class.
140 const_iterator end() const;
143 * This function will return the last certificate from collection.
145 * Note: There is no point to call this function if certificate
146 * collection is not sorted!
148 CertificatePtr back() const;
151 void sortCollection(void);
153 enum CollectionStatus
155 // Certificate collection are not sorted in any way
157 // Certificate collection creates certificate chain
159 // Cerfificate collection is not able to create certificate chain
160 COLLECTION_CHAIN_BROKEN,
163 CollectionStatus m_collectionStatus;
164 CertificateList m_certList;
167 typedef std::list<CertificateCollection> CertificateCollectionList;
169 } // namespace ValidationCore
171 #endif // _VALIDATION_CORE_CERTIFICATECHAIN_H_