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 #include "signature_algorithm_helper.h"
16
17 namespace OHOS {
18 namespace SignatureTools {
19 const SignatureAlgorithmHelper SignatureAlgorithmHelper::ECDSA_WITH_SHA256_INSTANCE{
20 SignatureAlgorithmId::ECDSA_WITH_SHA256, "EC", ContentDigestAlgorithm::SHA256,
21 {"SHA256withECDSA", nullptr} };
22
23 const SignatureAlgorithmHelper SignatureAlgorithmHelper::ECDSA_WITH_SHA384_INSTANCE{
24 SignatureAlgorithmId::ECDSA_WITH_SHA384, "EC", ContentDigestAlgorithm::SHA384,
25 {"SHA384withECDSA", nullptr} };
26
SignatureAlgorithmHelper()27 SignatureAlgorithmHelper::SignatureAlgorithmHelper() : m_id(SignatureAlgorithmId::ECDSA_WITH_SHA256),
28 m_keyAlgorithm(""),
29 m_contentDigestAlgorithm(ContentDigestAlgorithm::SHA256),
30 m_signatureAlgAndParams("", nullptr)
31 {
32 }
33
SignatureAlgorithmHelper(const SignatureAlgorithmHelper& other)34 SignatureAlgorithmHelper::SignatureAlgorithmHelper(const SignatureAlgorithmHelper& other) : m_id(other.m_id),
35 m_keyAlgorithm(other.m_keyAlgorithm),
36 m_contentDigestAlgorithm(other.m_contentDigestAlgorithm),
37 m_signatureAlgAndParams(other.m_signatureAlgAndParams.first, nullptr)
38 {
39 }
40
SignatureAlgorithmHelper(const SignatureAlgorithmId& id_, const std::string& keyAlg_, const ContentDigestAlgorithm& digestAlg_, const std::pair<std::string, void*>& sigParams_)41 SignatureAlgorithmHelper::SignatureAlgorithmHelper(const SignatureAlgorithmId& id_, const std::string& keyAlg_,
42 const ContentDigestAlgorithm& digestAlg_,
43 const std::pair<std::string, void*>& sigParams_)
44 : m_id(id_), m_keyAlgorithm(keyAlg_), m_contentDigestAlgorithm(digestAlg_), m_signatureAlgAndParams(sigParams_)
45 {
46 }
47
operator =(const SignatureAlgorithmHelper& other)48 SignatureAlgorithmHelper& SignatureAlgorithmHelper::operator=(const SignatureAlgorithmHelper& other)
49 {
50 if (this != &other) {
51 m_id = other.m_id;
52 m_keyAlgorithm = other.m_keyAlgorithm;
53 m_contentDigestAlgorithm = other.m_contentDigestAlgorithm;
54 m_signatureAlgAndParams.first = other.m_signatureAlgAndParams.first;
55 m_signatureAlgAndParams.second = other.m_signatureAlgAndParams.second;
56 }
57 return *this;
58 }
59
~SignatureAlgorithmHelper()60 SignatureAlgorithmHelper::~SignatureAlgorithmHelper()
61 {
62 }
63
FindById(const SignatureAlgorithmId id)64 const SignatureAlgorithmHelper* SignatureAlgorithmHelper::FindById(const SignatureAlgorithmId id)
65 {
66 if (id == SignatureAlgorithmId::ECDSA_WITH_SHA256) return &ECDSA_WITH_SHA256_INSTANCE;
67 if (id == SignatureAlgorithmId::ECDSA_WITH_SHA384) return &ECDSA_WITH_SHA384_INSTANCE;
68 return nullptr;
69 }
70 } // namespace SignatureTools
71 } // namespace OHOS