#pragma once
#include <whiteout/common_types.h>
#include <array>
#include <atomic>
#include <optional>
#include <span>
#include <string>
#include <unordered_map>
namespace whiteout::storages::casc {
class KeyRing {
public:
void addKey(u64 keyName, std::array<u8, 16> key);
void addKey(u64 keyName, const std::string& hexKey);
bool importFromString(const std::string& keyList);
bool importFromFile(const std::string& path);
const std::array<u8, 16>* findKey(u64 keyName) const;
std::optional<u64> firstMissingKey() const;
private:
std::unordered_map<u64, std::array<u8, 16>> m_keys;
mutable std::atomic<u64> m_firstMissing{0}; };
void salsa20Decrypt(std::span<u8> data, std::span<const u8, 16> key, std::span<const u8, 8> iv);
void arc4Transform(std::span<u8> data, std::span<const u8> key);
}