Skip to content

Commit

Permalink
Debug & Clone for token builders
Browse files Browse the repository at this point in the history
  • Loading branch information
tinrab committed Dec 21, 2023
1 parent aead671 commit db91a02
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 47 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni"
version = "0.1.40"
version = "0.1.43"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utility Library for Rust"
repository = "https://github.com/tinrab/bomboni"
Expand Down Expand Up @@ -38,9 +38,9 @@ tokio = ["bomboni_common/tokio"]
tonic = ["bomboni_proto/tonic", "bomboni_request/tonic"]

[dependencies]
bomboni_common = { path = "bomboni_common", version = "0.1.40" }
bomboni_common = { path = "bomboni_common", version = "0.1.43" }

bomboni_prost = { path = "bomboni_prost", version = "0.1.40", optional = true }
bomboni_proto = { path = "bomboni_proto", version = "0.1.40", optional = true }
bomboni_request = { path = "bomboni_request", version = "0.1.40", optional = true }
bomboni_template = { path = "bomboni_template", version = "0.1.40", optional = true }
bomboni_prost = { path = "bomboni_prost", version = "0.1.43", optional = true }
bomboni_proto = { path = "bomboni_proto", version = "0.1.43", optional = true }
bomboni_request = { path = "bomboni_request", version = "0.1.43", optional = true }
bomboni_template = { path = "bomboni_template", version = "0.1.43", optional = true }
6 changes: 3 additions & 3 deletions bomboni_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_common"
version = "0.1.40"
version = "0.1.43"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Common things for Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -21,10 +21,10 @@ tokio = ["dep:tokio"]
[dependencies]
regex = "1.10.2"

tokio = { version = "1.34.0", features = ["time", "sync"], optional = true }
tokio = { version = "1.35.1", features = ["time", "sync"], optional = true }
serde = { version = "1.0.193", features = ["derive"], optional = true }
sqlx = { version = "0.7", features = ["mysql"], optional = true }

[dev-dependencies]
serde_json = "1.0.108"
tokio = { version = "1.34.0", features = ["rt-multi-thread", "macros"] }
tokio = { version = "1.35.1", features = ["rt-multi-thread", "macros"] }
4 changes: 2 additions & 2 deletions bomboni_prost/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_prost"
version = "0.1.40"
version = "0.1.43"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilities for working with prost. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -19,6 +19,6 @@ convert_case = "0.6.0"
prost = "0.12.3"
prost-types = "0.12.3"
proc-macro2 = "1.0.70"
syn = { version = "2.0.39", features = ["full"] }
syn = { version = "2.0.42", features = ["full"] }
quote = "1.0.33"
prettyplease = "0.2.15"
8 changes: 4 additions & 4 deletions bomboni_proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_proto"
version = "0.1.40"
version = "0.1.43"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilities for working with Protobuf/gRPC. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -20,9 +20,9 @@ chrono = ["dep:chrono"]
json = ["dep:serde_json"]

[dependencies]
thiserror = "1.0.50"
thiserror = "1.0.51"
itertools = "0.12.0"
time = { version = "0.3.30", features = ["serde", "formatting", "parsing"] }
time = { version = "0.3.31", features = ["serde", "formatting", "parsing"] }
prost = "0.12.3"
serde = { version = "1.0.193", features = ["derive"] }
pot = "3.0.0"
Expand All @@ -36,5 +36,5 @@ serde_json = { version = "1.0.108", optional = true }
serde_json = "1.0.108"

[build-dependencies]
bomboni_prost = { path = "../bomboni_prost", version = "0.1.40" }
bomboni_prost = { path = "../bomboni_prost", version = "0.1.43" }
prost-build = "0.12.3"
14 changes: 7 additions & 7 deletions bomboni_request/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_request"
version = "0.1.40"
version = "0.1.43"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilities for working with API requests. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -19,23 +19,23 @@ testing = []
tonic = ["bomboni_proto/tonic", "dep:tonic"]

[dependencies]
bomboni_common = { path = "../bomboni_common", version = "0.1.40" }
bomboni_proto = { path = "../bomboni_proto", version = "0.1.40" }
thiserror = "1.0.50"
bomboni_common = { path = "../bomboni_common", version = "0.1.43" }
bomboni_proto = { path = "../bomboni_proto", version = "0.1.43" }
thiserror = "1.0.51"
itertools = "0.12.0"
time = { version = "0.3.30", features = ["formatting", "parsing"] }
time = { version = "0.3.31", features = ["formatting", "parsing"] }
prost = "0.12.3"
pest = "2.7.5"
pest_derive = "2.7.5"
base64ct = { version = "1.6.0", features = ["alloc"] }
aes-gcm = { version = "0.10.3", features = ["alloc"] }
blake2 = "0.10.6"
rsa = "0.9.5"
rsa = "0.9.6"
rand = "0.8.5"
regex = "1.10.2"

tonic = { version = "0.10.2", optional = true }
bomboni_request_derive = { path = "../bomboni_request_derive", version = "0.1.40", optional = true }
bomboni_request_derive = { path = "../bomboni_request_derive", version = "0.1.43", optional = true }

[dev-dependencies]
serde = { version = "1.0.193", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions bomboni_request/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,7 @@ mod tests {
})
}

#[derive(Clone)]
struct CustomPageTokenBuilder {}

impl PageTokenBuilder for CustomPageTokenBuilder {
Expand Down
1 change: 1 addition & 0 deletions bomboni_request/src/query/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct ListQueryConfig {
pub max_ordering_length: Option<usize>,
}

#[derive(Debug, Clone)]
pub struct ListQueryBuilder<P: PageTokenBuilder> {
schema: Schema,
options: ListQueryConfig,
Expand Down
22 changes: 14 additions & 8 deletions bomboni_request/src/query/page_token/aes256.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use aes_gcm::{
aead::{Aead, OsRng},
AeadCore, Aes256Gcm, Key, KeyInit,
};
use base64ct::{Base64, Base64Url, Encoding};

use super::{utility::make_page_key, FilterPageToken, PageTokenBuilder};
use crate::{
filter::Filter,
ordering::Ordering,
Expand All @@ -13,14 +8,19 @@ use crate::{
},
schema::SchemaMapped,
};

use super::{utility::make_page_key, FilterPageToken, PageTokenBuilder};
use aes_gcm::{
aead::{Aead, OsRng},
AeadCore, Aes256Gcm, Key, KeyInit,
};
use base64ct::{Base64, Base64Url, Encoding};
use std::fmt::{self, Debug, Formatter};

const NONCE_LENGTH: usize = 12;

/// AES-256-GCM page token builder.
/// The page token is encrypted using the query parameters as the key.
/// This is useful for ensuring that the page token was generated for the same paging rules.
#[derive(Clone)]
pub struct Aes256PageTokenBuilder {
url_safe: bool,
}
Expand Down Expand Up @@ -101,6 +101,12 @@ impl PageTokenBuilder for Aes256PageTokenBuilder {
}
}

impl Debug for Aes256PageTokenBuilder {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Aes256PageTokenBuilder").finish()
}
}

#[cfg(test)]
mod tests {
use crate::testing::schema::UserItem;
Expand Down
14 changes: 10 additions & 4 deletions bomboni_request/src/query/page_token/base64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use base64ct::{Base64, Base64Url, Encoding};

use super::{FilterPageToken, PageTokenBuilder};
use crate::{
filter::Filter,
ordering::Ordering,
Expand All @@ -8,10 +7,11 @@ use crate::{
page_token::utility::get_page_filter,
},
};

use super::{FilterPageToken, PageTokenBuilder};
use base64ct::{Base64, Base64Url, Encoding};
use std::fmt::{self, Debug, Formatter};

/// Page token builder for Base64-encoded tokens.
#[derive(Clone)]
pub struct Base64PageTokenBuilder {
url_safe: bool,
}
Expand Down Expand Up @@ -61,6 +61,12 @@ impl PageTokenBuilder for Base64PageTokenBuilder {
}
}

impl Debug for Base64PageTokenBuilder {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Base64PageTokenBuilder").finish()
}
}

#[cfg(test)]
mod tests {
use crate::testing::schema::UserItem;
Expand Down
11 changes: 9 additions & 2 deletions bomboni_request/src/query/page_token/plain.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use super::{utility::get_page_filter, FilterPageToken, PageTokenBuilder};
use crate::{
filter::Filter,
ordering::Ordering,
query::error::{QueryError, QueryResult},
schema::SchemaMapped,
};

use super::{utility::get_page_filter, FilterPageToken, PageTokenBuilder};
use std::fmt::{self, Debug, Formatter};

/// Plain text page token builder.
/// Used only for testing.
#[derive(Clone)]
pub struct PlainPageTokenBuilder {}

impl PageTokenBuilder for PlainPageTokenBuilder {
Expand Down Expand Up @@ -39,3 +40,9 @@ impl PageTokenBuilder for PlainPageTokenBuilder {
Ok(format!("{page_filter}"))
}
}

impl Debug for PlainPageTokenBuilder {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("PlainPageTokenBuilder").finish()
}
}
11 changes: 9 additions & 2 deletions bomboni_request/src/query/page_token/rsa.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::{utility::make_page_key, FilterPageToken, PageTokenBuilder};
use crate::{
filter::Filter,
ordering::Ordering,
Expand All @@ -6,14 +7,14 @@ use crate::{
page_token::utility::get_page_filter,
},
};

use super::{utility::make_page_key, FilterPageToken, PageTokenBuilder};
use base64ct::{Base64, Base64Url, Encoding};
use rsa::{Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey};
use std::fmt::{self, Debug, Formatter};

const PARAMS_KEY_LENGTH: usize = 32;

/// Page token builder for RSA-encrypted tokens.
#[derive(Clone)]
pub struct RsaPageTokenBuilder {
private_key: RsaPrivateKey,
public_key: RsaPublicKey,
Expand Down Expand Up @@ -96,6 +97,12 @@ impl PageTokenBuilder for RsaPageTokenBuilder {
}
}

impl Debug for RsaPageTokenBuilder {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("RsaPageTokenBuilder").finish()
}
}

#[cfg(test)]
mod tests {
use std::sync::OnceLock;
Expand Down
1 change: 1 addition & 0 deletions bomboni_request/src/query/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct SearchQueryConfig {
pub max_ordering_length: Option<usize>,
}

#[derive(Debug, Clone)]
pub struct SearchQueryBuilder<P: PageTokenBuilder> {
schema: Schema,
options: SearchQueryConfig,
Expand Down
4 changes: 2 additions & 2 deletions bomboni_request_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_request_derive"
version = "0.1.40"
version = "0.1.43"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Provides derive implementations for Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -17,6 +17,6 @@ proc-macro = true
[dependencies]
itertools = "0.12.0"
proc-macro2 = { version = "1.0.70", features = ["proc-macro"] }
syn = "2.0.39"
syn = "2.0.42"
quote = "1.0.33"
darling = "0.20.3"
6 changes: 3 additions & 3 deletions bomboni_request_derive/src/parse/message/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn expand(options: &ParseOptions, fields: &[ParseField]) -> syn::Result<Toke
quote! {
impl #ident #type_params #where_clause {
#[allow(clippy::ignored_unit_patterns)]
fn parse_search_query<P: PageTokenBuilder #query_token_type >(
pub fn parse_search_query<P: PageTokenBuilder #query_token_type >(
source: #source,
query_builder: &SearchQueryBuilder<P>
) -> Result<Self, RequestError> {
Expand All @@ -157,7 +157,7 @@ pub fn expand(options: &ParseOptions, fields: &[ParseField]) -> syn::Result<Toke
quote! {
impl #ident #type_params #where_clause {
#[allow(clippy::ignored_unit_patterns)]
fn parse_list_query<P: PageTokenBuilder #query_token_type >(
pub fn parse_list_query<P: PageTokenBuilder #query_token_type >(
source: #source,
query_builder: &ListQueryBuilder<P>
) -> Result<Self, RequestError> {
Expand Down Expand Up @@ -746,7 +746,7 @@ fn expand_extract_source_field(field: &ParseField) -> TokenStream {
});
}

// Purposefully clone source on each parse.
// Intentionally clone source on each parse.
// Could be optimized in the future.
quote! {
let target = source.clone() #extract;
Expand Down
8 changes: 4 additions & 4 deletions bomboni_template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_template"
version = "0.1.40"
version = "0.1.43"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilities for working Handlebars templates. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -17,11 +17,11 @@ path = "src/lib.rs"
testing = []

[dependencies]
bomboni_common = { path = "../bomboni_common", version = "0.1.40" }
bomboni_proto = { version = "0.1.40", path = "../bomboni_proto", features = [
bomboni_common = { path = "../bomboni_common", version = "0.1.43" }
bomboni_proto = { version = "0.1.43", path = "../bomboni_proto", features = [
"json",
] }
thiserror = "1.0.50"
thiserror = "1.0.51"
itertools = "0.12.0"
handlebars = "4.5.0"
serde = { version = "1.0.193", features = ["derive"] }
Expand Down

0 comments on commit db91a02

Please sign in to comment.