1 /*
2  * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef SIGNATRUETOOLS_PKCS7_CONTEXT_H
16 #define SIGNATRUETOOLS_PKCS7_CONTEXT_H
17 
18 #include <vector>
19 #include <string>
20 #include "openssl/pkcs7.h"
21 #include "openssl/x509.h"
22 #include "byte_buffer.h"
23 #include "matching_result.h"
24 
25 namespace OHOS {
26 namespace SignatureTools {
27 
28 using CertChain = std::vector<X509*>;
29 using Pkcs7CertChains = std::vector<CertChain>;
30 
31 struct Pkcs7Context {
32     bool needWriteCrl;
33     int32_t digestAlgorithm = 0;
34     MatchingResult matchResult;
35     std::string certIssuer;
36     PKCS7* p7;
37     Pkcs7CertChains certChain;
38     ByteBuffer content;
Pkcs7ContextOHOS::SignatureTools::Pkcs7Context39     Pkcs7Context()
40         : needWriteCrl(false), digestAlgorithm(0), matchResult(), certIssuer(),
41         p7(nullptr), certChain(), content()
42     {
43     }
~Pkcs7ContextOHOS::SignatureTools::Pkcs7Context44     ~Pkcs7Context()
45     {
46         if (p7 != nullptr) {
47             PKCS7_free(p7);
48             p7 = nullptr;
49         }
50         for (auto certChain : certChain) {
51             for (auto cert : certChain) {
52                 X509_free(cert);
53             }
54         }
55         certChain.clear();
56     }
57 };
58 } // namespace SignatureTools
59 } // namespace OHOS
60 #endif // SIGNATRUETOOLS_PKCS7_CONTEXT_H
61