#ifndef CHROMEOS_ASH_SERVICES_DEVICE_SYNC_CRYPTAUTH_KEY_H_
#define CHROMEOS_ASH_SERVICES_DEVICE_SYNC_CRYPTAUTH_KEY_H_
#include <optional>
#include "base/values.h"
#include "chromeos/ash/services/device_sync/proto/cryptauth_common.pb.h"
namespace ash {
namespace device_sync {
class CryptAuthKey {
public:
enum Status { kActive, kInactive };
static std::optional<CryptAuthKey> FromDictionary(
const base::Value::Dict& value);
CryptAuthKey(const std::string& symmetric_key,
Status status,
cryptauthv2::KeyType type,
const std::optional<std::string>& handle = std::nullopt);
CryptAuthKey(const std::string& public_key,
const std::string& private_key,
Status status,
cryptauthv2::KeyType type,
const std::optional<std::string>& handle = std::nullopt);
CryptAuthKey(const CryptAuthKey&);
~CryptAuthKey();
bool IsSymmetricKey() const;
bool IsAsymmetricKey() const;
Status status() const { return status_; }
cryptauthv2::KeyType type() const { return type_; }
const std::string& symmetric_key() const {
DCHECK(IsSymmetricKey());
return symmetric_key_;
}
const std::string& public_key() const {
DCHECK(IsAsymmetricKey());
return public_key_;
}
const std::string& private_key() const {
DCHECK(IsAsymmetricKey());
return private_key_;
}
const std::string& handle() const { return handle_; }
void set_status(Status status) { status_ = status; }
base::Value::Dict AsSymmetricKeyDictionary() const;
base::Value::Dict AsAsymmetricKeyDictionary() const;
bool operator==(const CryptAuthKey& other) const;
bool operator!=(const CryptAuthKey& other) const;
private:
std::string symmetric_key_;
std::string public_key_;
std::string private_key_;
Status status_;
cryptauthv2::KeyType type_;
std::string handle_;
};
}
}
#endif