#pragma once #include "crypto/crypto.h" #include #include #include #include #include namespace vn::auth { constexpr std::uint8_t ROLE_ANONYMOUS = 0; constexpr std::uint8_t ROLE_READ = 1; constexpr std::uint8_t ROLE_WRITE = 2; constexpr std::uint8_t ROLE_UNKNOWN = 255; // --------------------------------------------------------------------------- // Client keys // --------------------------------------------------------------------------- struct Key { std::string name; std::vector seed; PublicKey public_key{}; std::string fingerprint; }; fs::path key_dir(); fs::path key_path(std::string_view name); std::optional load_key(std::string_view name); std::optional generate_key(std::string_view name); std::vector list_key_names(); // --------------------------------------------------------------------------- // Per-user key selection // --------------------------------------------------------------------------- fs::path auth_dir(); std::string normalize_target(std::string_view target); bool set_key(std::string_view target, std::string_view key_name); bool remove_key(std::string_view target); std::vector list_credential_lines(); bool local_key_exists(std::string_view name); std::optional key_for_url(std::string_view url); // --------------------------------------------------------------------------- // Server access policy // --------------------------------------------------------------------------- struct AccessEntry { PublicKey public_key{}; std::string name; std::uint8_t role = ROLE_READ; }; struct Access { bool valid = true; std::int64_t error_line = 0; bool anonymous_read = false; std::vector entries; }; Access empty_access(); fs::path access_path(const fs::path& repo_root); Access load_access(const fs::path& repo_root); bool write_access(const fs::path& repo_root, const Access& access); bool add_access(const fs::path& repo_root, std::uint8_t role, const PublicKey& public_key, std::string_view name); bool remove_access(const fs::path& repo_root, std::string_view fingerprint, std::string_view name); bool set_anonymous(const fs::path& repo_root, bool enabled); std::uint8_t role_for(const Access& access, const PublicKey* public_key); } // namespace vn::auth