2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
2018-07-03 21:29:04 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
|
|
|
|
namespace td {
|
2018-07-22 00:03:21 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class DbKey {
|
2020-01-19 01:02:56 +01:00
|
|
|
enum class Type { Empty, RawKey, Password };
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
Type type() const {
|
|
|
|
return type_;
|
|
|
|
}
|
2020-01-19 01:02:56 +01:00
|
|
|
|
|
|
|
public:
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_empty() const {
|
2020-01-19 01:02:56 +01:00
|
|
|
return type_ == Type::Empty;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-01-19 01:02:56 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_raw_key() const {
|
2020-01-19 01:02:56 +01:00
|
|
|
return type_ == Type::RawKey;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-01-19 01:02:56 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_password() const {
|
2020-01-19 01:02:56 +01:00
|
|
|
return type_ == Type::Password;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-01-19 01:02:56 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
CSlice data() const {
|
|
|
|
return data_;
|
|
|
|
}
|
2020-01-19 01:02:56 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
static DbKey raw_key(string raw_key) {
|
|
|
|
DbKey res;
|
2020-01-19 01:02:56 +01:00
|
|
|
res.type_ = Type::RawKey;
|
2018-12-31 20:04:05 +01:00
|
|
|
res.data_ = std::move(raw_key);
|
|
|
|
return res;
|
|
|
|
}
|
2020-01-19 01:02:56 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
static DbKey password(string password) {
|
|
|
|
DbKey res;
|
2020-01-19 01:02:56 +01:00
|
|
|
res.type_ = Type::Password;
|
2018-12-31 20:04:05 +01:00
|
|
|
res.data_ = std::move(password);
|
|
|
|
return res;
|
|
|
|
}
|
2020-01-19 01:02:56 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
static DbKey empty() {
|
|
|
|
return DbKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-01-19 01:02:56 +01:00
|
|
|
Type type_{Type::Empty};
|
2018-12-31 20:04:05 +01:00
|
|
|
string data_;
|
|
|
|
};
|
2018-07-22 00:03:21 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|