Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds support for re-exporting crate #79

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

---

## [0.2.0] - 2024-10-30

### Changed

- Breaking: de-anchor veil imports, to allow for reimporting.

This might cause issues in some very rare cases, but generally shouldn't require any changes.

---

## [0.1.7] - 2023-11-20

### Changed
Expand All @@ -21,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Updated to syn v2

[Unreleased]: https://github.com/primait/veil/compare/0.1.7...HEAD

[Unreleased]: https://github.com/primait/veil/compare/0.2.0...HEAD
[0.2.0]: https://github.com/primait/veil/compare/0.1.7...0.2.0
[0.1.7]: https://github.com/primait/veil/compare/0.1.6...0.1.7
[0.1.6]: https://github.com/primait/veil/compare/0.1.5...0.1.6
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "veil"
version = "0.1.7"
version = "0.2.0"
edition = "2021"
description = "Rust derive macro for redacting sensitive data in `std::fmt::Debug`"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -28,7 +28,7 @@ name = "disable_redaction"
required-features = ["toggle"]

[dependencies]
veil-macros = { path = "veil-macros", version = "=0.1.7" }
veil-macros = { path = "veil-macros", version = "=0.2.0" }
once_cell = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Add to your Cargo.toml:

```toml
[dependencies]
veil = "0.1.7"
veil = "0.2.0"
```

Usage documentation can be found [here](https://docs.rs/veil).
Expand Down
17 changes: 9 additions & 8 deletions src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ pub enum RedactSpecialization {
/// This could be improved & rid of in a number of different ways in the future:
///
/// * Once specialization is stabilized, we can use a trait to override redacting behavior for some types,
/// one of which would be [`Option<T>`].
/// one of which would be [`Option<T>`].
///
/// * Once std::ptr::metadata and friends are stabilized, we could use it to unsafely cast the dyn Debug pointer
/// to a concrete [`Option<T>`] and redact it directly. Probably not the best idea.
/// to a concrete [`Option<T>`] and redact it directly. Probably not the best idea.
///
/// * Once trait upcasting is stabilized, we could use it to upcast the dyn Debug pointer to a dyn Any and then
/// downcast it to a concrete [`Option<T>`] and redact it directly.
/// downcast it to a concrete [`Option<T>`] and redact it directly.
Option,
}

Expand Down Expand Up @@ -127,12 +127,13 @@ impl RedactionTarget<'_> {
}
}
}
impl ToString for RedactionTarget<'_> {
fn to_string(&self) -> String {

impl Display for RedactionTarget<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match self {
RedactionTarget::Debug { this, alternate: false } => format!("{:?}", this),
RedactionTarget::Debug { this, alternate: true } => format!("{:#?}", this),
RedactionTarget::Display(this) => this.to_string(),
RedactionTarget::Debug { this, alternate: false } => write!(f, "{:?}", this),
RedactionTarget::Debug { this, alternate: true } => write!(f, "{:#?}", this),
RedactionTarget::Display(this) => write!(f, "{}", this),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/redactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,9 @@ impl RedactorBuilder {
Ok(Redactor(flags))
}
}

impl Default for RedactorBuilder {
fn default() -> Self {
Self::new()
}
}
2 changes: 1 addition & 1 deletion veil-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "veil-macros"
version = "0.1.7"
version = "0.2.0"
edition = "2021"
description = "Veil procedural macros"
license = "MIT OR Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions veil-macros/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ pub enum RedactionLength {
impl quote::ToTokens for RedactionLength {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
match self {
RedactionLength::Full => quote! { ::veil::private::RedactionLength::Full }.to_tokens(tokens),
RedactionLength::Partial => quote! { ::veil::private::RedactionLength::Partial }.to_tokens(tokens),
RedactionLength::Full => quote! { veil::private::RedactionLength::Full }.to_tokens(tokens),
RedactionLength::Partial => quote! { veil::private::RedactionLength::Partial }.to_tokens(tokens),
RedactionLength::Fixed(n) => {
let n = n.get();
quote! { ::veil::private::RedactionLength::Fixed(::core::num::NonZeroU8::new(#n).unwrap()) }
quote! { veil::private::RedactionLength::Fixed(::core::num::NonZeroU8::new(#n).unwrap()) }
.to_tokens(tokens)
}
}
Expand Down
14 changes: 7 additions & 7 deletions veil-macros/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,26 @@ pub(crate) fn generate_redact_call(
unused.redacted_something();

let specialization = if is_option {
quote! { ::std::option::Option::Some(::veil::private::RedactSpecialization::Option) }
quote! { ::std::option::Option::Some(veil::private::RedactSpecialization::Option) }
} else {
quote! { ::std::option::Option::None }
};

if field_flags.display {
// std::fmt::Display
quote! {
&::veil::private::RedactionFormatter {
this: ::veil::private::RedactionTarget::Display(#field_accessor),
flags: ::veil::private::RedactFlags { #field_flags },
&veil::private::RedactionFormatter {
this: veil::private::RedactionTarget::Display(#field_accessor),
flags: veil::private::RedactFlags { #field_flags },
specialization: #specialization
}
}
} else {
// std::fmt::Debug
quote! {
&::veil::private::RedactionFormatter {
this: ::veil::private::RedactionTarget::Debug { this: #field_accessor, alternate },
flags: ::veil::private::RedactFlags { #field_flags },
&veil::private::RedactionFormatter {
this: veil::private::RedactionTarget::Debug { this: #field_accessor, alternate },
flags: veil::private::RedactFlags { #field_flags },
specialization: #specialization
}
}
Expand Down
10 changes: 5 additions & 5 deletions veil-macros/src/redactable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ fn try_derive(mut item: syn::DeriveInput) -> Result<TokenStream, syn::Error> {
let name_ident = &item.ident;
let (impl_generics, ty_generics, where_clause) = item.generics.split_for_impl();
Ok(quote! {
impl #impl_generics ::veil::Redactable for #name_ident #ty_generics #where_clause {
impl #impl_generics veil::Redactable for #name_ident #ty_generics #where_clause {
fn redact(&self) -> String {
::veil::private::derived_redactable(
veil::private::derived_redactable(
self,
::veil::private::RedactFlags { #flags }
veil::private::RedactFlags { #flags }
)
}

fn redact_into(&self, buffer: &mut dyn ::std::fmt::Write) -> ::std::fmt::Result {
buffer.write_str(
::veil::private::derived_redactable(
veil::private::derived_redactable(
self,
::veil::private::RedactFlags { #flags }
veil::private::RedactFlags { #flags }
)
.as_str()
)
Expand Down