77925e949117c88f84bfc943fc38747d02d371b6
[platform/core/security/cert-svc.git] / src / vcore / SignatureFinder.h
1 /*
2  * Copyright (c) 2016 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        SignatureFinder.h
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       Search for author-signature.xml and signatureN.xml files.
21  *              This class is WAC 2.0 specific and shuld be moved to
22  *              wrt-installer.
23  */
24 #ifndef _VALIDATION_CORE_SIGNATUREFINDER_H_
25 #define _VALIDATION_CORE_SIGNATUREFINDER_H_
26
27 #include <set>
28 #include <string>
29
30 namespace ValidationCore {
31
32 class SignatureFileInfo {
33 public:
34         SignatureFileInfo(const std::string &fileName, int num)
35                 : m_fileName(fileName)
36                 , m_fileNumber(num)
37         {}
38
39         std::string getFileName() const
40         {
41                 return m_fileName;
42         }
43
44         int getFileNumber() const
45         {
46                 return m_fileNumber;
47         }
48
49         bool operator<(const SignatureFileInfo &second) const
50         {
51                 return m_fileNumber < second.m_fileNumber;
52         }
53
54 private:
55         std::string m_fileName;
56         int m_fileNumber;
57 };
58
59 typedef std::set<SignatureFileInfo> SignatureFileInfoSet;
60
61 class SignatureFinder {
62 public:
63         enum Result {
64                 NO_ERROR,
65                 ERROR_OPENING_DIR,
66                 ERROR_READING_DIR,
67                 ERROR_ISTREAM
68         };
69
70         SignatureFinder() = delete;
71         explicit SignatureFinder(const std::string &dir);
72
73         virtual ~SignatureFinder();
74
75         Result find(SignatureFileInfoSet &set);
76
77 private:
78         class Impl;
79         Impl *m_impl;
80
81         SignatureFinder(const SignatureFinder &);
82         const SignatureFinder &operator=(const SignatureFinder &);
83 };
84
85 } // namespace ValidationCore
86
87 #endif // _VALIDATION_CORE_SIGNATUREFINDER_H_