Coverage Report

Created: 2025-12-14 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rnp/src/lib/enc_material.hpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2024 [Ribose Inc](https://www.ribose.com).
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without modification,
6
 * are permitted provided that the following conditions are met:
7
 *
8
 * 1.  Redistributions of source code must retain the above copyright notice,
9
 *     this list of conditions and the following disclaimer.
10
 *
11
 * 2.  Redistributions in binary form must reproduce the above copyright notice,
12
 *     this list of conditions and the following disclaimer in the documentation
13
 *     and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#ifndef RNP_ENC_MATERIAL_HPP_
28
#define RNP_ENC_MATERIAL_HPP_
29
30
#include "types.h"
31
#include "defaults.h"
32
33
typedef struct pgp_packet_body_t pgp_packet_body_t;
34
35
namespace pgp {
36
37
class EncMaterial {
38
  public:
39
#if defined(ENABLE_CRYPTO_REFRESH)
40
    pgp_pkesk_version_t version = PGP_PKSK_V3;
41
    pgp_symm_alg_t      salg = PGP_SA_UNKNOWN;
42
#endif
43
680k
    virtual ~EncMaterial(){};
44
45
    virtual bool parse(pgp_packet_body_t &pkt) noexcept = 0;
46
    virtual void write(pgp_packet_body_t &pkt) const = 0;
47
48
    static std::unique_ptr<EncMaterial> create(pgp_pubkey_alg_t alg);
49
};
50
51
class RSAEncMaterial : public EncMaterial {
52
  public:
53
    rsa::Encrypted enc;
54
55
    bool parse(pgp_packet_body_t &pkt) noexcept override;
56
    void write(pgp_packet_body_t &pkt) const override;
57
};
58
59
class EGEncMaterial : public EncMaterial {
60
  public:
61
    eg::Encrypted enc;
62
63
    bool parse(pgp_packet_body_t &pkt) noexcept override;
64
    void write(pgp_packet_body_t &pkt) const override;
65
};
66
67
class SM2EncMaterial : public EncMaterial {
68
  public:
69
    sm2::Encrypted enc;
70
71
    bool parse(pgp_packet_body_t &pkt) noexcept override;
72
    void write(pgp_packet_body_t &pkt) const override;
73
};
74
75
class ECDHEncMaterial : public EncMaterial {
76
  public:
77
    ecdh::Encrypted enc;
78
79
    bool parse(pgp_packet_body_t &pkt) noexcept override;
80
    void write(pgp_packet_body_t &pkt) const override;
81
};
82
83
#if defined(ENABLE_CRYPTO_REFRESH)
84
class X25519EncMaterial : public EncMaterial {
85
  public:
86
    pgp_x25519_encrypted_t enc;
87
88
    bool parse(pgp_packet_body_t &pkt) noexcept override;
89
    void write(pgp_packet_body_t &pkt) const override;
90
};
91
#endif
92
93
#if defined(ENABLE_PQC)
94
class MlkemEcdhEncMaterial : public EncMaterial {
95
    pgp_pubkey_alg_t alg_;
96
97
  public:
98
    pgp_kyber_ecdh_encrypted_t enc;
99
100
6.03k
    MlkemEcdhEncMaterial(pgp_pubkey_alg_t alg) : alg_(alg)
101
6.03k
    {
102
6.03k
    }
103
104
    bool parse(pgp_packet_body_t &pkt) noexcept override;
105
    void write(pgp_packet_body_t &pkt) const override;
106
};
107
#endif
108
109
} // namespace pgp
110
111
#endif // RNP_ENC_MATERIAL_HPP_