turnstile 1.0.12

One-way encryption.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::fs;

use sodiumoxide::crypto::box_;
use anyhow::{self, Context};

use crate::io::key_path;

use super::base62;

pub fn keygen(keydir: &str) -> anyhow::Result<()> {
    let (target_pkey, target_skey ) = box_::gen_keypair();
    let b62_pkey = base62::encode(&target_pkey.0);
    let b62_skey = base62::encode(&target_skey.0);
    let path = key_path(keydir, &b62_pkey);

    fs::write(&path, b62_skey).context(format!("unable to open '{path}' for writing a key"))?;
    Ok(())
}