Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Signing 2 - hc keygen #974

Merged
merged 19 commits into from
Feb 11, 2019
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

members = [
"cli",
"common",
"conductor",
"conductor_api",
"core_api_c_binding",
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = ["Holochain Core Dev Team <devcore@holochain.org>"]

[dependencies]
holochain_net = { path = "../net" }
holochain_common = { path = "../common" }
holochain_core_types = { path = "../core_types" }
holochain_core = { path = "../core" }
holochain_cas_implementations = { path = "../cas_implementations" }
Expand Down
8 changes: 2 additions & 6 deletions cli/src/cli/keygen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use error::DefaultResult;
use holochain_common::paths::keys_directory;
use holochain_dpki::{
bundle::KeyBundle,
keypair::{Keypair, SEEDSIZE},
Expand All @@ -9,7 +10,6 @@ use rpassword;
use std::{
fs::{create_dir_all, File},
io::prelude::*,
path::PathBuf,
};

pub fn keygen() -> DefaultResult<()> {
Expand All @@ -36,11 +36,7 @@ pub fn keygen() -> DefaultResult<()> {
)
.unwrap();

let path = match directories::UserDirs::new() {
Some(user_dirs) => user_dirs.home_dir().join(".holochain").join("keys"),
None => PathBuf::new(),
};

let path = keys_directory();
create_dir_all(path.clone())?;
let path = path.join(keypair.pub_keys);
let mut file = File::create(path.clone())?;
Expand Down
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern crate holochain_cas_implementations;
extern crate holochain_common;
extern crate holochain_conductor_api;
extern crate holochain_core;
extern crate holochain_core_types;
Expand Down
8 changes: 8 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "holochain_common"
version = "0.0.3"
authors = ["Holochain Core Dev Team <devcore@holochain.org>"]
edition = "2018"

[dependencies]
directories = "1.0"
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod paths;
23 changes: 23 additions & 0 deletions common/src/paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::path::PathBuf;

pub const QUALIFIER: &'static str = "org";
pub const ORGANIZATION: &'static str = "holochain";
pub const APPLICATION: &'static str = "holochain";
pub const KEYS_DIRECTORY: &'static str = "keys";

/// Returns the path to the root config directory for all of Holochain.
/// If we can get a user directory it will be an XDG compliant path
/// like "/home/peter/.config/holochain".
/// If it can't get a user directory it will default to "/etc/holochain".
pub fn config_root() -> PathBuf {
directories::ProjectDirs::from(QUALIFIER, ORGANIZATION, APPLICATION)
.and_then(|dirs| Some(dirs.config_dir().to_owned()))
lucksus marked this conversation as resolved.
Show resolved Hide resolved
.or(Some(PathBuf::new().join("/etc").join(APPLICATION)))
.unwrap()
lucksus marked this conversation as resolved.
Show resolved Hide resolved
}

/// Returns the path to where agent keys are stored and looked for by default.
/// Something like "~/.config/holochain/keys".
pub fn keys_directory() -> PathBuf {
config_root().join(KEYS_DIRECTORY)
}