/src/rnp/src/lib/userid.hpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2017-2025 [Ribose Inc](https://www.ribose.com). |
3 | | * All rights reserved. |
4 | | * |
5 | | * Redistribution and use in source and binary forms, with or without |
6 | | * modification, are permitted provided that the following conditions |
7 | | * are met: |
8 | | * 1. Redistributions of source code must retain the above copyright |
9 | | * notice, this list of conditions and the following disclaimer. |
10 | | * 2. Redistributions in binary form must reproduce the above copyright |
11 | | * notice, this list of conditions and the following disclaimer in the |
12 | | * documentation and/or other materials provided with the distribution. |
13 | | * |
14 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
15 | | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
16 | | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS |
18 | | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
19 | | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
20 | | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
21 | | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
22 | | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | | * POSSIBILITY OF SUCH DAMAGE. |
25 | | */ |
26 | | |
27 | | #ifndef RNP_USERID_HPP_ |
28 | | #define RNP_USERID_HPP_ |
29 | | |
30 | | #include <vector> |
31 | | #include "rawpacket.hpp" |
32 | | #include "signature.hpp" |
33 | | #include "librepgp/stream-packet.h" |
34 | | |
35 | | namespace rnp { |
36 | | |
37 | | /* userid, built on top of userid packet structure */ |
38 | | class UserID { |
39 | | private: |
40 | | pgp::SigIDs sigs_; /* all signatures related to this userid */ |
41 | | public: |
42 | | pgp_userid_pkt_t pkt; /* User ID or User Attribute packet as it was loaded */ |
43 | | RawPacket rawpkt; /* Raw packet contents */ |
44 | | std::string str; /* Human-readable representation of the userid */ |
45 | | bool valid; /* User ID is valid, i.e. has valid, non-expired self-signature */ |
46 | | bool revoked; |
47 | | Revocation revocation; |
48 | | |
49 | 0 | UserID() : valid(false), revoked(false){}; |
50 | | UserID(const pgp_userid_pkt_t &pkt); |
51 | | |
52 | | size_t sig_count() const; |
53 | | const pgp::SigID &get_sig(size_t idx) const; |
54 | | bool has_sig(const pgp::SigID &id) const; |
55 | | void add_sig(const pgp::SigID &sig, bool begin = false); |
56 | | void replace_sig(const pgp::SigID &id, const pgp::SigID &newsig); |
57 | | bool del_sig(const pgp::SigID &id); |
58 | | void clear_sigs(); |
59 | | |
60 | | /* No userid, i.e. direct-key signature */ |
61 | | static const uint32_t None = (uint32_t) -1; |
62 | | /* look only for primary userids */ |
63 | | static const uint32_t Primary = (uint32_t) -2; |
64 | | /* look for any uid, except UserID::None) */ |
65 | | static const uint32_t Any = (uint32_t) -3; |
66 | | }; |
67 | | |
68 | | } // namespace rnp |
69 | | |
70 | | #endif |