keyforkd: swap minicbor for serde + bincode

This commit is contained in:
Ryan Heywood 2023-08-25 02:47:54 -05:00
parent 067de52e4b
commit a9209ee36a
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
5 changed files with 39 additions and 46 deletions

69
Cargo.lock generated
View File

@ -41,6 +41,15 @@ dependencies = [
"rustc-demangle", "rustc-demangle",
] ]
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "bip39" name = "bip39"
version = "2.0.0" version = "2.0.0"
@ -276,10 +285,11 @@ dependencies = [
name = "keyforkd" name = "keyforkd"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bincode",
"dirs", "dirs",
"keyfork-frame", "keyfork-frame",
"keyfork-mnemonic-util", "keyfork-mnemonic-util",
"minicbor", "serde",
"thiserror", "thiserror",
"tokio", "tokio",
"tower", "tower",
@ -327,26 +337,6 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "minicbor"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7005aaf257a59ff4de471a9d5538ec868a21586534fff7f85dd97d4043a6139"
dependencies = [
"minicbor-derive",
]
[[package]]
name = "minicbor-derive"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1154809406efdb7982841adb6311b3d095b46f78342dd646736122fe6b19e267"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.1" version = "0.7.1"
@ -431,7 +421,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.29", "syn",
] ]
[[package]] [[package]]
@ -542,9 +532,23 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.183" version = "1.0.186"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" checksum = "9f5db24220c009de9bd45e69fb2938f4b6d2df856aa9304ce377b3180f83b7c1"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ad697f7e0b65af4983a4ce8f56ed5b357e8d3c36651bf6a7e13639c17b8e670"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
@ -608,17 +612,6 @@ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.29" version = "2.0.29"
@ -647,7 +640,7 @@ checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.29", "syn",
] ]
[[package]] [[package]]
@ -702,7 +695,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.29", "syn",
] ]
[[package]] [[package]]
@ -754,7 +747,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.29", "syn",
] ]
[[package]] [[package]]

View File

@ -11,10 +11,11 @@ tracing = ["tower/tracing", "tokio/tracing", "dep:tracing", "dep:tracing-subscri
multithread = ["tokio/rt-multi-thread"] multithread = ["tokio/rt-multi-thread"]
[dependencies] [dependencies]
bincode = "1.3.3"
dirs = "5.0.1" dirs = "5.0.1"
keyfork-frame = { version = "0.1.0", path = "../keyfork-frame" } keyfork-frame = { version = "0.1.0", path = "../keyfork-frame" }
keyfork-mnemonic-util = { version = "0.1.0", path = "../keyfork-mnemonic-util" } keyfork-mnemonic-util = { version = "0.1.0", path = "../keyfork-mnemonic-util" }
minicbor = { version = "0.19.1", features = ["derive", "std"] } serde = { version = "1.0.186", features = ["derive"] }
thiserror = "1.0.47" thiserror = "1.0.47"
tokio = { version = "1.32.0", features = ["io-util", "macros", "rt", "io-std", "net", "fs", "signal"] } tokio = { version = "1.32.0", features = ["io-util", "macros", "rt", "io-std", "net", "fs", "signal"] }
tower = { version = "0.4.13", features = ["tokio", "util"] } tower = { version = "0.4.13", features = ["tokio", "util"] }

View File

@ -13,11 +13,11 @@ use tracing_subscriber::{
}; };
mod error; mod error;
mod service;
mod server; mod server;
mod service;
use error::KeycloakdError; use error::KeycloakdError;
use service::Keyforkd;
use server::UnixServer; use server::UnixServer;
use service::Keyforkd;
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>; type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;

View File

@ -11,7 +11,7 @@ async fn read_path_from_socket(
socket: &mut UnixStream, socket: &mut UnixStream,
) -> Result<DerivablePath, Box<dyn std::error::Error + Send>> { ) -> Result<DerivablePath, Box<dyn std::error::Error + Send>> {
let data = try_decode_from(socket).await.unwrap(); let data = try_decode_from(socket).await.unwrap();
let path: DerivablePath = minicbor::decode(&data[..]).unwrap(); let path: DerivablePath = bincode::deserialize(&data[..]).unwrap();
Ok(path) Ok(path)
} }

View File

@ -1,14 +1,13 @@
use std::{future::Future, pin::Pin, task::Poll, sync::Arc}; use std::{future::Future, pin::Pin, task::Poll, sync::Arc};
use keyfork_mnemonic_util::Mnemonic; use keyfork_mnemonic_util::Mnemonic;
use minicbor::{Decode, Encode};
use tower::Service; use tower::Service;
use thiserror::Error; use thiserror::Error;
use serde::{Serialize, Deserialize};
#[derive(Encode, Decode, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct DerivablePath { pub struct DerivablePath {
#[n(0)] pub(crate) path: Vec<Vec<u8>>,
path: Vec<Vec<u8>>,
} }
// TODO: move DerivablePath into a models crate for clients to produce? // TODO: move DerivablePath into a models crate for clients to produce?