pasejo 2026.2.22

passage re-implementation in Rust for teams
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// SPDX-FileCopyrightText: The pasejo Authors
// SPDX-License-Identifier: 0BSD

use crate::cli::environment_variables;
use anyhow::Context;
use std::env;

pub fn download_public_key(username: &str) -> anyhow::Result<String> {
    let codeberg_host = env::var(environment_variables::CODEBERG_HOST)
        .unwrap_or_else(|_| String::from("codeberg.org"));
    let key = ureq::get(format!("https://{codeberg_host}/{username}.keys"))
        .call()
        .context("Downloading public key from codeberg failed")?
        .body_mut()
        .read_to_string()?;
    Ok(String::from(key.trim()))
}