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 false if base64 string is broken
68 * (is not encoded in base64 format) or one from certificate
69 * is broken (is not encoded in der format).
71 * This function will add new certificate to collection.
72 * This function DOES NOT clean collection.
74 bool load(const std::string &base64);
77 * This function will return all certificates from
78 * collection encoded in base64 format.
80 std::string toBase64String() const;
83 * This will return all certificate from collection.
85 CertificateList getCertificateList() const;
88 * This function will return true if certificates
89 * in in this structure were sorted and create
92 * Note: You MUST sort certificates first.
97 * This function will return true if all certificate are
98 * able to create certificate chain.
100 * This function will sort certificates if collection
103 * Note: This function will make all iterators invalid.
108 * This function will return Certificate chain.
110 * First certificate on the list is EndEntity certificate.
112 * Last certificate on the list is RootCA certificate or
113 * CA certificate if RootCA is not present.
115 * Note: You MUST sort certificates first and
116 * check if certificates creates proper chain.
118 CertificateList getChain() const;
121 * It returns size of certificate collection.
126 * Return true if collection is empty.
131 * This will return end iterator to internal collection.
133 * Note: this iterator will lose validity if you call non const
134 * method on CertificateCollection class.
136 const_iterator begin() const;
139 * This will return end iterator to internal collection.
141 * Note: this iterator will lose validity if you call non const
142 * method on CertificateCollection class.
144 const_iterator end() const;
147 * This function will return the last certificate from collection.
149 * Note: There is no point to call this function if certificate
150 * collection is not sorted!
152 CertificatePtr back() const;
155 void sortCollection(void);
157 enum CollectionStatus
159 // Certificate collection are not sorted in any way
161 // Certificate collection creates certificate chain
163 // Cerfificate collection is not able to create certificate chain
164 COLLECTION_CHAIN_BROKEN,
167 CollectionStatus m_collectionStatus;
168 CertificateList m_certList;
171 typedef std::list<CertificateCollection> CertificateCollectionList;
173 } // namespace ValidationCore
175 #endif // _VALIDATION_CORE_CERTIFICATECHAIN_H_