summaryrefslogtreecommitdiffstats
path: root/letmein/src/command/genkey.rs
blob: 87d8a4be327c61e1e046b76fa57c6f1d06d18000 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// -*- coding: utf-8 -*-
//
// Copyright (C) 2024 Michael Büsch <m@bues.ch>
//
// Licensed under the Apache License version 2.0
// or the MIT license, at your option.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use anyhow as ah;
use letmein_conf::Config;
use letmein_proto::{secure_random, Key, UserId};
use std::sync::Arc;

pub async fn run_genkey(conf: Arc<Config>, user: Option<UserId>) -> ah::Result<()> {
    let user = user.unwrap_or_else(|| conf.default_user());
    let key: Key = secure_random();
    let key: Vec<String> = key.iter().map(|b| format!("{b:02X}")).collect();
    let key: String = key.join("");
    println!("{user} = {key}");
    Ok(())
}

// vim: ts=4 sw=4 expandtab
bues.ch cgit interface