Browse Source

Separate out core functionality.

tags/v0.1.0
Thomas Kerber 2 years ago
parent
commit
9e9c4ccf9a
10 changed files with 73 additions and 48 deletions
  1. 1
    0
      .gitignore
  2. 15
    8
      Cargo.lock
  3. 1
    8
      Cargo.toml
  4. 14
    0
      goblin-core/Cargo.toml
  5. 0
    0
      goblin-core/src/crypto.rs
  6. 1
    3
      goblin-core/src/format.rs
  7. 8
    2
      goblin-core/src/keyring.rs
  8. 18
    0
      goblin-core/src/lib.rs
  9. 0
    0
      goblin-core/src/ser.rs
  10. 15
    27
      src/main.rs

+ 1
- 0
.gitignore View File

@@ -1,2 +1,3 @@
target/
*/Cargo.lock
**/*.rs.bk

+ 15
- 8
Cargo.lock View File

@@ -3,15 +3,8 @@ name = "goblin"
version = "0.1.0"
dependencies = [
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"gcrypt 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"goblin-core 0.1.0",
"rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tar 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -85,6 +78,20 @@ dependencies = [
"libgcrypt-sys 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "goblin-core"
version = "0.1.0"
dependencies = [
"gcrypt 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tar 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "gpg-error"
version = "0.2.2"

+ 1
- 8
Cargo.toml View File

@@ -4,13 +4,6 @@ version = "0.1.0"
authors = ["Thomas Kerber <tk@drwx.org>"]

[dependencies]
tar = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"
gcrypt = "*"
tempdir = "*"
rand = "*"
hex = "*"
log = {version="*", features=["release_max_level_debug"]}
env_logger = "*"
goblin-core = {version="*", path="goblin-core"}

+ 14
- 0
goblin-core/Cargo.toml View File

@@ -0,0 +1,14 @@
[package]
name = "goblin-core"
version = "0.1.0"
authors = ["Thomas Kerber <tk@drwx.org>"]

[dependencies]
tar = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"
gcrypt = "*"
tempdir = "*"
hex = "*"
log = {version="*", features=["release_max_level_debug"]}

src/crypto.rs → goblin-core/src/crypto.rs View File


src/format.rs → goblin-core/src/format.rs View File

@@ -186,9 +186,7 @@ impl Commit {
encrypt(data, &vault.key, &mut enc)?;
commit.hash = Hash::new(&enc[..]);
let path = format!("{}.commit", commit.hash.to_hex());
create_umask()
.open(vault.path(&path))?
.write_all(&enc[..])?;
create_umask().open(vault.path(&path))?.write_all(&enc[..])?;
vault.modified = true;
vault.metadata.current = commit.hash;
vault.write_metadata()?;

src/keyring.rs → goblin-core/src/keyring.rs View File

@@ -29,7 +29,10 @@ impl Keyring {
}

fn from_commit(vault: &Vault, mut commit: Commit) -> Result<Self> {
debug!("constructing keyring from commit {:?}", commit.hash.to_hex());
debug!(
"constructing keyring from commit {:?}",
commit.hash.to_hex()
);
let mut hist_chain = vec![];
let mut previous = commit.previous(vault)?;
while previous.len() == 1 {
@@ -50,7 +53,10 @@ impl Keyring {
);
for commit in previous {
info!(" {}", commit.hash.to_hex());
previous_keyrings.push((commit.hash.to_hex(), Keyring::from_commit(vault, commit)?));
previous_keyrings.push((
commit.hash.to_hex(),
Keyring::from_commit(vault, commit)?,
));
}
debug!("recursively reconstructing and renaming");
// Merges keep a copy of each predecessor, where <path> is moved to

+ 18
- 0
goblin-core/src/lib.rs View File

@@ -0,0 +1,18 @@

extern crate tar;
extern crate tempdir;
extern crate hex;
#[macro_use]
extern crate log;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate gcrypt;

mod crypto;
pub mod format;
pub mod keyring;
mod ser;

pub use crypto::{Result, Error, Hash};

src/ser.rs → goblin-core/src/ser.rs View File


+ 15
- 27
src/main.rs View File

@@ -1,23 +1,9 @@
#![allow(dead_code)]

extern crate tar;
extern crate tempdir;
extern crate rand;
extern crate hex;
#[macro_use]
extern crate log;
extern crate env_logger;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate gcrypt;

mod format;
mod crypto;
mod ser;
mod keyring;
extern crate rand;
extern crate goblin_core;

use goblin_core::format::{Vault, Delta};
use goblin_core::keyring;
use std::path::PathBuf;

fn main() {
@@ -25,25 +11,27 @@ fn main() {

let f = PathBuf::from("foo.vault");
if f.exists() {
let vault = format::Vault::open(f, "foobar".as_bytes().to_owned()).unwrap();
let vault = Vault::open(f, "foobar".as_bytes().to_owned()).unwrap();
let krs = keyring::State::new(vault).unwrap();
for (k, v) in krs.iter() {
println!("'{}' => {}", k, match v {
&keyring::Entry::Value(ref s) => format!("'{}'", s),
&keyring::Entry::Ref(ref s) => format!("-> '{}'", s),
});
println!(
"'{}' => {}",
k,
match v {
&keyring::Entry::Value(ref s) => format!("'{}'", s),
&keyring::Entry::Ref(ref s) => format!("-> '{}'", s),
}
);
}
} else {
let vault = format::Vault::create(f, "foobar".as_bytes().to_owned()).unwrap();
let vault = Vault::create(f, "foobar".as_bytes().to_owned()).unwrap();
let mut krs = keyring::State::new(vault).unwrap();
//krs.apply(format::Delta::Insert("foo".to_owned(), "bar".to_owned()));
//krs.apply(format::Delta::Insert("bar".to_owned(), "baz".to_owned()));
use rand::{thread_rng, Rng};
for _ in 0..10000 {
for _ in 0..5 {
let k = thread_rng().gen_ascii_chars().take(10).collect();
let v = thread_rng().gen_ascii_chars().take(10).collect();
krs.apply(format::Delta::Insert(k, v));
krs.apply(Delta::Insert(k, v));
}
krs.commit().unwrap();
}

Loading…
Cancel
Save