class Localhost::Authority

def self.path(env = ENV, old_root: nil)

After May 2025, the old_root option may be removed.

compliant directory.
directory (~/.localhost/) exists, it is moved into the new XDG Basedir
Ensures that the directory to store the certificate exists. If the legacy

of $XDG_STATE_HOME, or ~/.local/state/ when that's not defined.
Where to store the key pair on the filesystem. This is a subdirectory
def self.path(env = ENV, old_root: nil)
	path = File.expand_path("localhost.rb", env.fetch("XDG_STATE_HOME", "~/.local/state"))
	
	unless File.directory?(path)
		FileUtils.mkdir_p(path, mode: 0700)
	end
	
	# Migrates the legacy dir ~/.localhost/ to the XDG compliant directory
	old_root ||= File.expand_path("~/.localhost")
	if File.directory?(old_root)
		FileUtils.mv(Dir.glob(File.join(old_root, "*")), path, force: true)
		FileUtils.rmdir(old_root)
	end
	
	return path
end