| 1 |
/* Copyright (c) 2021, 2026, Oracle and/or its affiliates. |
| 2 |
|
| 3 |
This program is free software; you can redistribute it and/or modify |
| 4 |
it under the terms of the GNU General Public License, version 2.0, |
| 5 |
as published by the Free Software Foundation. |
| 6 |
|
| 7 |
This program is designed to work with certain software (including |
| 8 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 9 |
as designated in a particular file or component or in included license |
| 10 |
documentation. The authors of MySQL hereby grant you an additional |
| 11 |
permission to link the program and your derivative works with the |
| 12 |
separately licensed software that they have either included with |
| 13 |
the program or referenced in the documentation. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License, version 2.0, for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program; if not, write to the Free Software |
| 22 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 23 |
|
| 24 |
#include "meta.h" |
| 25 |
|
| 26 |
namespace keyring_common { |
| 27 |
namespace meta { |
| 28 |
|
| 29 |
/** Constructor */ |
| 30 |
Metadata::Metadata(const std::string key_id, const std::string owner_id) |
| 31 |
: key_id_(key_id), owner_id_(owner_id), hash_key_() { |
| 32 |
valid_ = !(key_id_.empty() && owner_id_.empty()); |
| 33 |
create_hash_key(); |
| 34 |
} |
| 35 |
|
| 36 |
Metadata::Metadata(const char *key_id, const char *owner_id) |
| 37 |
: Metadata(key_id != nullptr ? std::string{key_id} : std::string{}, |
| 38 |
owner_id != nullptr ? std::string{owner_id} : std::string{}) {} |
| 39 |
|
| 40 |
Metadata::Metadata() : Metadata(std::string{}, std::string{}) {} |
| 41 |
|
| 42 |
/** Copy constructor */ |
| 43 |
Metadata::Metadata(const Metadata &src) |
| 44 |
: Metadata(src.key_id_, src.owner_id_) {} |
| 45 |
|
| 46 |
/** Move constructor */ |
| 47 |
Metadata::Metadata(Metadata &&src) noexcept { |
| 48 |
std::swap(src.key_id_, key_id_); |
| 49 |
std::swap(src.owner_id_, owner_id_); |
| 50 |
std::swap(src.hash_key_, hash_key_); |
| 51 |
std::swap(src.valid_, valid_); |
| 52 |
} |
| 53 |
|
| 54 |
/** Assignment operator */ |
| 55 |
Metadata &Metadata::operator=(const Metadata &src) = default; |
| 56 |
|
| 57 |
Metadata &Metadata::operator=(Metadata &&src) noexcept { |
| 58 |
std::swap(src.key_id_, key_id_); |
| 59 |
std::swap(src.owner_id_, owner_id_); |
| 60 |
std::swap(src.hash_key_, hash_key_); |
| 61 |
std::swap(src.valid_, valid_); |
| 62 |
|
| 63 |
return *this; |
| 64 |
} |
| 65 |
|
| 66 |
/** Destructor */ |
| 67 |
Metadata::~Metadata() { valid_ = false; } |
| 68 |
|
| 69 |
/** Get key ID */ |
| 70 |
const std::string Metadata::key_id() const { return key_id_; } |
| 71 |
|
| 72 |
/** Get owner info */ |
| 73 |
const std::string Metadata::owner_id() const { return owner_id_; } |
| 74 |
|
| 75 |
/** Validity of metadata object */ |
| 76 |
bool Metadata::valid() const { return valid_; } |
| 77 |
|
| 78 |
/** create hash key */ |
| 79 |
void Metadata::create_hash_key() { |
| 80 |
if (valid_) { |
| 81 |
hash_key_ = key_id_; |
| 82 |
if (!owner_id_.empty()) { |
| 83 |
hash_key_.push_back('\0'); |
| 84 |
hash_key_.append(owner_id_); |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
} // namespace meta |
| 90 |
} // namespace keyring_common |