#pragma once
#include "common.hpp"
#include <string>
#include <vector>
#include <memory>
#include <array>
#include <cstdint>
#include <cstring>



class VaultKey {
    SecureBuffer<32> key_;
public:
    VaultKey() = default;
    explicit VaultKey(SecureBuffer<32> key) : key_(std::move(key)) {}
    ~VaultKey() = default;
    VaultKey(VaultKey&&) = default;
    VaultKey& operator=(VaultKey&&) = default;
    VaultKey(const VaultKey&) = delete;
    VaultKey& operator=(const VaultKey&) = delete;
    const uint8_t* data() const { return key_.data(); }
    size_t size() const { return key_.size(); }
    std::string_view view() const {
        return std::string_view(reinterpret_cast<const char*>(key_.data()), key_.size());
    }
    static VaultKey from_raw(const uint8_t* data, size_t len) {
        SecureBuffer<32> sb;
        std::memcpy(sb.data(), data, std::min(len, sb.size()));
        return VaultKey(std::move(sb));
    }
};

VaultKey load_key_from_file(const std::string& path);
VaultKey load_key_from_shield();
std::string decrypt_vault(const std::string& encrypted_path, const VaultKey& key);
std::string decrypt_vault(const std::string& encrypted_path, const std::string& key_file);
std::string decrypt_vault_data(const std::vector<uint8_t>& encrypted_data, const VaultKey& key);
