Browse Source

Separate out core functionality.

Thomas Kerber 1 year 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 @@
1 1
 target/
2
+*/Cargo.lock
2 3
 **/*.rs.bk

+ 15
- 8
Cargo.lock View File

@@ -3,15 +3,8 @@ name = "goblin"
3 3
 version = "0.1.0"
4 4
 dependencies = [
5 5
  "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
6
- "gcrypt 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
7
- "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
8
- "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
6
+ "goblin-core 0.1.0",
9 7
  "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
10
- "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
11
- "serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
12
- "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
13
- "tar 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
14
- "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
15 8
 ]
16 9
 
17 10
 [[package]]
@@ -85,6 +78,20 @@ dependencies = [
85 78
  "libgcrypt-sys 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
86 79
 ]
87 80
 
81
+[[package]]
82
+name = "goblin-core"
83
+version = "0.1.0"
84
+dependencies = [
85
+ "gcrypt 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
86
+ "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
87
+ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
88
+ "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
89
+ "serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
90
+ "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
91
+ "tar 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
92
+ "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
93
+]
94
+
88 95
 [[package]]
89 96
 name = "gpg-error"
90 97
 version = "0.2.2"

+ 1
- 8
Cargo.toml View File

@@ -4,13 +4,6 @@ version = "0.1.0"
4 4
 authors = ["Thomas Kerber <tk@drwx.org>"]
5 5
 
6 6
 [dependencies]
7
-tar = "*"
8
-serde = "*"
9
-serde_json = "*"
10
-serde_derive = "*"
11
-gcrypt = "*"
12
-tempdir = "*"
13 7
 rand = "*"
14
-hex = "*"
15
-log = {version="*", features=["release_max_level_debug"]}
16 8
 env_logger = "*"
9
+goblin-core = {version="*", path="goblin-core"}

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

@@ -0,0 +1,14 @@
1
+[package]
2
+name = "goblin-core"
3
+version = "0.1.0"
4
+authors = ["Thomas Kerber <tk@drwx.org>"]
5
+
6
+[dependencies]
7
+tar = "*"
8
+serde = "*"
9
+serde_json = "*"
10
+serde_derive = "*"
11
+gcrypt = "*"
12
+tempdir = "*"
13
+hex = "*"
14
+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 {
186 186
         encrypt(data, &vault.key, &mut enc)?;
187 187
         commit.hash = Hash::new(&enc[..]);
188 188
         let path = format!("{}.commit", commit.hash.to_hex());
189
-        create_umask()
190
-            .open(vault.path(&path))?
191
-            .write_all(&enc[..])?;
189
+        create_umask().open(vault.path(&path))?.write_all(&enc[..])?;
192 190
         vault.modified = true;
193 191
         vault.metadata.current = commit.hash;
194 192
         vault.write_metadata()?;

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

@@ -29,7 +29,10 @@ impl Keyring {
29 29
     }
30 30
 
31 31
     fn from_commit(vault: &Vault, mut commit: Commit) -> Result<Self> {
32
-        debug!("constructing keyring from commit {:?}", commit.hash.to_hex());
32
+        debug!(
33
+            "constructing keyring from commit {:?}",
34
+            commit.hash.to_hex()
35
+        );
33 36
         let mut hist_chain = vec![];
34 37
         let mut previous = commit.previous(vault)?;
35 38
         while previous.len() == 1 {
@@ -50,7 +53,10 @@ impl Keyring {
50 53
             );
51 54
             for commit in previous {
52 55
                 info!("    {}", commit.hash.to_hex());
53
-                previous_keyrings.push((commit.hash.to_hex(), Keyring::from_commit(vault, commit)?));
56
+                previous_keyrings.push((
57
+                    commit.hash.to_hex(),
58
+                    Keyring::from_commit(vault, commit)?,
59
+                ));
54 60
             }
55 61
             debug!("recursively reconstructing and renaming");
56 62
             // 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 @@
1
+
2
+extern crate tar;
3
+extern crate tempdir;
4
+extern crate hex;
5
+#[macro_use]
6
+extern crate log;
7
+extern crate serde;
8
+#[macro_use]
9
+extern crate serde_derive;
10
+extern crate serde_json;
11
+extern crate gcrypt;
12
+
13
+mod crypto;
14
+pub mod format;
15
+pub mod keyring;
16
+mod ser;
17
+
18
+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 @@
1
-#![allow(dead_code)]
2
-
3
-extern crate tar;
4
-extern crate tempdir;
5
-extern crate rand;
6
-extern crate hex;
7
-#[macro_use]
8
-extern crate log;
9 1
 extern crate env_logger;
10
-extern crate serde;
11
-#[macro_use]
12
-extern crate serde_derive;
13
-extern crate serde_json;
14
-extern crate gcrypt;
15
-
16
-mod format;
17
-mod crypto;
18
-mod ser;
19
-mod keyring;
2
+extern crate rand;
3
+extern crate goblin_core;
20 4
 
5
+use goblin_core::format::{Vault, Delta};
6
+use goblin_core::keyring;
21 7
 use std::path::PathBuf;
22 8
 
23 9
 fn main() {
@@ -25,25 +11,27 @@ fn main() {
25 11
 
26 12
     let f = PathBuf::from("foo.vault");
27 13
     if f.exists() {
28
-        let vault = format::Vault::open(f, "foobar".as_bytes().to_owned()).unwrap();
14
+        let vault = Vault::open(f, "foobar".as_bytes().to_owned()).unwrap();
29 15
         let krs = keyring::State::new(vault).unwrap();
30 16
         for (k, v) in krs.iter() {
31
-            println!("'{}' => {}", k, match v {
32
-                &keyring::Entry::Value(ref s) => format!("'{}'", s),
33
-                &keyring::Entry::Ref(ref s) => format!("-> '{}'", s),
34
-            });
17
+            println!(
18
+                "'{}' => {}",
19
+                k,
20
+                match v {
21
+                    &keyring::Entry::Value(ref s) => format!("'{}'", s),
22
+                    &keyring::Entry::Ref(ref s) => format!("-> '{}'", s),
23
+                }
24
+            );
35 25
         }
36 26
     } else {
37
-        let vault = format::Vault::create(f, "foobar".as_bytes().to_owned()).unwrap();
27
+        let vault = Vault::create(f, "foobar".as_bytes().to_owned()).unwrap();
38 28
         let mut krs = keyring::State::new(vault).unwrap();
39
-        //krs.apply(format::Delta::Insert("foo".to_owned(), "bar".to_owned()));
40
-        //krs.apply(format::Delta::Insert("bar".to_owned(), "baz".to_owned()));
41 29
         use rand::{thread_rng, Rng};
42 30
         for _ in 0..10000 {
43 31
             for _ in 0..5 {
44 32
                 let k = thread_rng().gen_ascii_chars().take(10).collect();
45 33
                 let v = thread_rng().gen_ascii_chars().take(10).collect();
46
-                krs.apply(format::Delta::Insert(k, v));
34
+                krs.apply(Delta::Insert(k, v));
47 35
             }
48 36
             krs.commit().unwrap();
49 37
         }

Loading…
Cancel
Save