Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Commit

Permalink
Migrate from rustc_serialize/cbor to serde/serde_cbor
Browse files Browse the repository at this point in the history
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
valpackett committed Jun 3, 2017
1 parent d1e93f9 commit 0aaa63e
Show file tree
Hide file tree
Showing 18 changed files with 413 additions and 246 deletions.
1 change: 0 additions & 1 deletion .cargo/config

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 5 additions & 3 deletions capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
22 changes: 10 additions & 12 deletions capi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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::*;
Expand Down Expand Up @@ -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]
}
}

Expand All @@ -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()
}
Loading

0 comments on commit 0aaa63e

Please sign in to comment.