aboutsummaryrefslogtreecommitdiffstats
path: root/letmein/src/command/genkey.rs
blob: 747b35d950aa774db9ffe7fc0c9c0d7e8ee9907c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// -*- 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;

/// Generate a new truly random and secure user key.
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