8007c0c316ec19af3759b1cf1112d97436e80c97
[platform/core/security/cert-svc.git] / vcore / src / vcore / VerificationStatus.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  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
18  * @version     0.2
19  * @file        VerficationStatus.cpp
20  * @brief       OCSP/CRL status.
21  */
22 #include <vcore/VerificationStatus.h>
23
24 namespace ValidationCore {
25
26 VerificationStatusSet::VerificationStatusSet()
27     : m_verdictMap(0)
28 {}
29
30 void VerificationStatusSet::add(VerificationStatus status) {
31     m_verdictMap |= status;
32 }
33
34 bool VerificationStatusSet::contains(VerificationStatus status) const {
35     return m_verdictMap & status;
36 }
37
38 bool VerificationStatusSet::isEmpty() const {
39     return 0 == m_verdictMap;
40 }
41
42 void VerificationStatusSet::operator+=(const VerificationStatusSet &second) {
43     m_verdictMap |= second.m_verdictMap;
44 }
45
46 void VerificationStatusSet::reset() {
47     m_verdictMap = 0;
48 }
49
50 VerificationStatus VerificationStatusSet::convertToStatus() const
51 {
52     if (m_verdictMap & VERIFICATION_STATUS_REVOKED) {
53         return VERIFICATION_STATUS_REVOKED;
54     }
55
56     if (m_verdictMap & VERIFICATION_STATUS_VERIFICATION_ERROR) {
57         return VERIFICATION_STATUS_VERIFICATION_ERROR;
58     }
59
60     if (m_verdictMap & VERIFICATION_STATUS_ERROR) {
61         return VERIFICATION_STATUS_ERROR;
62     }
63
64     if (m_verdictMap & VERIFICATION_STATUS_UNKNOWN) {
65         return VERIFICATION_STATUS_UNKNOWN;
66     }
67
68     if (m_verdictMap & VERIFICATION_STATUS_CONNECTION_FAILED) {
69         return VERIFICATION_STATUS_CONNECTION_FAILED;
70     }
71
72     if (m_verdictMap & VERIFICATION_STATUS_NOT_SUPPORT) {
73         return VERIFICATION_STATUS_NOT_SUPPORT;
74     }
75
76     if (m_verdictMap & VERIFICATION_STATUS_GOOD) {
77         return VERIFICATION_STATUS_GOOD;
78     }
79
80     return VERIFICATION_STATUS_ERROR;
81 }
82 } // namespace ValidationCore