Permalink
Browse files

Migrate from rustc_serialize/cbor to serde/serde_cbor

F I N A L L Y!

The new serialization is more efficient (byte arrays are used for all
Vec<u8>), more flexible (enum variants that have named fields use names
instead of positions), and Serde is just the way forward.
  • Loading branch information...
myfreeweb committed Jun 3, 2017
1 parent d1e93f9 commit 0aaa63e580b8498033224f70bf3addfdf7241045
Showing with 413 additions and 246 deletions.
  1. +0 −1 .cargo/config
  2. +2 −0 README.md
  3. +5 −3 capi/Cargo.toml
  4. +10 −12 capi/src/lib.rs
  5. +264 −137 cli/Cargo.lock
  6. +9 −4 cli/Cargo.toml
  7. +4 −4 cli/src/interact.rs
  8. +4 −2 cli/src/main.rs
  9. +6 −7 cli/src/util.rs
  10. +14 −5 core/Cargo.toml
  11. +10 −11 core/src/attachments.rs
  12. +32 −15 core/src/data.rs
  13. +24 −19 core/src/encvault.rs
  14. +4 −10 core/src/import.rs
  15. +8 −2 core/src/lib.rs
  16. +6 −11 core/src/output.rs
  17. +10 −2 core/src/result.rs
  18. +1 −1 rusterpassword
View

This file was deleted.

Oops, something went wrong.
View
@@ -1,3 +1,5 @@
NOTE: if you've been using freepass before June 03, 2017: you need to checkout the `serde-migration` git tag, build the CLI, and `mergein` your vault into a new one using that particular version.
# freepass [![unlicense](https://img.shields.io/badge/un-license-green.svg?style=flat)](http://unlicense.org)
The free password manager for power users.
View
@@ -15,11 +15,13 @@ crate-type = [ "dylib", "staticlib" ]
[dependencies]
freepass-core = { version = "0", path = "../core", default-features = false, features = [] }
secstr = { version = "0.2.1", features = ["cbor-serialize", "libsodium-sys"] }
cbor = "0"
secstr = { git = "https://github.com/myfreeweb/secstr.git", rev = "rustc_serialize", features = ["serde", "cbor-serialize", "libsodium-sys"] }
serde_cbor = "0.6"
sodiumoxide = "0"
rusterpassword = "0"
rusterpassword-capi = { version = "0", path = "../rusterpassword/capi" }
colorhash256 = "0"
rustc-serialize = "0"
libc = "0.2"
[replace]
"secstr:0.3.0" = { git = "https://github.com/myfreeweb/secstr.git", rev = "rustc_serialize", features = ["serde", "cbor-serialize", "libsodium-sys"] }
View
@@ -1,5 +1,7 @@
#![allow(no_mangle_generic_items)]
extern crate libc;
extern crate cbor;
extern crate serde_cbor;
extern crate secstr;
extern crate rusterpassword_capi;
extern crate freepass_core;
@@ -8,7 +10,6 @@ pub use rusterpassword_capi::*;
use std::{ptr, fs, mem, slice};
use std::ffi::*;
use cbor::{Encoder, Decoder};
use libc::*;
use secstr::*;
use freepass_core::data::*;
@@ -119,16 +120,13 @@ pub unsafe extern fn freepass_free_entry_names_iterator<'a>(iter_c: *mut Box<Ite
#[no_mangle]
pub extern fn freepass_vault_get_entry_cbor(vault_c: *const DecryptedVault, name_c: *const c_char) -> CVector {
if let Ok((mut entry_cbor, metadata)) = from_c![obj vault_c].get_entry_cbor(from_c![cstr name_c]) {
// Optimization: avoid decoding entry just to re-encode it
entry_cbor.insert(0, 0x82); // Array of length 2
{
let mut e = Encoder::from_writer(&mut entry_cbor);
e.encode(&[metadata]).unwrap();
}
to_c![vec entry_cbor]
// Optimization: avoid decoding entry just to re-encode it
entry_cbor.insert(0, 0x82); // Array of length 2
serde_cbor::ser::to_writer(&mut entry_cbor, &[metadata]).unwrap();
to_c![vec entry_cbor]
} else {
let empty = Vec::new();
to_c![vec empty]
let empty = Vec::new();
to_c![vec empty]
}
}
@@ -139,6 +137,6 @@ pub unsafe extern fn freepass_free_entry_cbor(cbor_c: CVector) {
#[no_mangle]
pub extern fn freepass_vault_put_entry_cbor(vault_c: *mut DecryptedVault, name_c: *const c_char, cbor_c: *const u8, cbor_len_c: size_t) {
let (entry, mut metadata) = Decoder::from_bytes(from_c![slice cbor_c, cbor_len_c]).decode::<(Entry, EntryMetadata)>().next().unwrap().unwrap();
let (entry, mut metadata) = serde_cbor::from_slice::<Vec<(Entry, EntryMetadata)>>(from_c![slice cbor_c, cbor_len_c]).unwrap().pop().unwrap();
from_c![mut obj vault_c].put_entry(from_c![cstr name_c], &entry, &mut metadata).unwrap()
}
Oops, something went wrong.

0 comments on commit 0aaa63e

Please sign in to comment.