Skip to content

Commit

Permalink
apply some clippy lint where it makes sense
Browse files Browse the repository at this point in the history
  • Loading branch information
ptondereau committed Jun 5, 2024
1 parent 71f4350 commit 9043f42
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 59 deletions.
2 changes: 1 addition & 1 deletion biscuit-auth/examples/verifying_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
&hex::decode("acdd6d5b53bfee478bf689f8e012fe7988bf755e3d7c5152947abc149bc20189").unwrap(),
)
.unwrap();
let token = biscuit_auth::Biscuit::from(&data[..], &root).unwrap();
let token = biscuit_auth::Biscuit::from(&data[..], root).unwrap();

println!("Token content:");
for i in 0..token.block_count() {
Expand Down
2 changes: 1 addition & 1 deletion biscuit-auth/src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl FromStr for PublicKey {

impl Display for PublicKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ed25519/{}", hex::encode(&self.to_bytes()))
write!(f, "ed25519/{}", hex::encode(self.to_bytes()))
}
}

Expand Down
20 changes: 10 additions & 10 deletions biscuit-auth/src/datalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ impl Rule {

CombineIt::new(variables, &self.body, facts, symbols)
.map(move |(origin, variables)| {
let mut temporary_symbols = TemporarySymbolTable::new(&symbols);
let mut temporary_symbols = TemporarySymbolTable::new(symbols);
for e in self.expressions.iter() {
match e.evaluate(&variables, &mut temporary_symbols) {
Ok(Term::Bool(true)) => {}
Ok(Term::Bool(false)) => return Ok((origin, variables, false)),
Ok(_) => return Err(error::Expression::InvalidType.into()),
Ok(_) => return Err(error::Expression::InvalidType),

Check warning on line 143 in biscuit-auth/src/datalog/mod.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/datalog/mod.rs#L143

Added line #L143 was not covered by tests
Err(e) => {
//println!("expr returned {:?}", res);
return Err(e);
Expand Down Expand Up @@ -207,7 +207,7 @@ impl Rule {
for (_, variables) in CombineIt::new(variables, &self.body, fact_it, symbols) {
found = true;

let mut temporary_symbols = TemporarySymbolTable::new(&symbols);
let mut temporary_symbols = TemporarySymbolTable::new(symbols);
for e in self.expressions.iter() {
match e.evaluate(&variables, &mut temporary_symbols) {
Ok(Term::Bool(true)) => {}
Expand Down Expand Up @@ -775,7 +775,7 @@ impl FactSet {
.flatten()
}

pub fn iter_all<'a>(&'a self) -> impl Iterator<Item = (&Origin, &Fact)> + Clone {
pub fn iter_all(&self) -> impl Iterator<Item = (&Origin, &Fact)> + Clone {
self.inner
.iter()
.flat_map(move |(ids, facts)| facts.iter().map(move |fact| (ids, fact)))
Expand Down Expand Up @@ -829,7 +829,7 @@ impl RuleSet {
}
}

pub fn iter_all<'a>(&'a self) -> impl Iterator<Item = (&TrustedOrigins, &Rule)> + Clone {
pub fn iter_all(&self) -> impl Iterator<Item = (&TrustedOrigins, &Rule)> + Clone {
self.inner
.iter()
.flat_map(move |(ids, rules)| rules.iter().map(move |(_, rule)| (ids, rule)))
Expand Down Expand Up @@ -918,7 +918,7 @@ pub fn contains_v4_op(expressions: &[Expression]) -> bool {
_ => return false,
}
}
return false;
false
})
})
}
Expand Down Expand Up @@ -1255,7 +1255,7 @@ mod tests {
),
0,
&[0].iter().collect(),
&syms,
syms,
).unwrap()
.iter_all()
.map(|(_, fact)| fact.clone())
Expand Down Expand Up @@ -1576,7 +1576,7 @@ mod tests {
println!("\t{}", syms.print_fact(fact));
}

assert!(res.len() == 0);
assert!(res.is_empty());

let res = w.query_rule(
rule(
Expand All @@ -1597,7 +1597,7 @@ mod tests {
println!("\t{}", syms.print_fact(fact));
}

assert!(res.len() == 0);
assert!(res.is_empty());
}

#[test]
Expand Down Expand Up @@ -1693,6 +1693,6 @@ mod tests {
for (_, fact) in res.iter_all() {
println!("\t{}", syms.print_fact(fact));
}
assert!(res.len() == 0);
assert!(res.is_empty());
}
}
4 changes: 2 additions & 2 deletions biscuit-auth/src/datalog/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl SymbolTable {
match term {
Term::Variable(i) => format!("${}", self.print_symbol_default(*i as u64)),
Term::Integer(i) => i.to_string(),
Term::Str(index) => format!("\"{}\"", self.print_symbol_default(*index as u64)),
Term::Str(index) => format!("\"{}\"", self.print_symbol_default(*index)),
Term::Date(d) => OffsetDateTime::from_unix_timestamp(*d as i64)
.ok()
.and_then(|t| t.format(&Rfc3339).ok())
Expand Down Expand Up @@ -328,7 +328,7 @@ impl<'a> TemporarySymbolTable<'a> {

pub fn insert(&mut self, s: &str) -> SymbolIndex {
if let Some(index) = self.base.get(s) {
return index as u64;
return index;

Check warning on line 331 in biscuit-auth/src/datalog/symbol.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/datalog/symbol.rs#L331

Added line #L331 was not covered by tests
}

match self.symbols.iter().position(|sym| sym.as_str() == s) {
Expand Down
2 changes: 1 addition & 1 deletion biscuit-auth/src/format/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub fn proto_snapshot_block_to_token_block(

let external_key = match &input.external_key {
None => None,
Some(key) => Some(PublicKey::from_proto(&key)?),
Some(key) => Some(PublicKey::from_proto(key)?),

Check warning on line 192 in biscuit-auth/src/format/convert.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/format/convert.rs#L192

Added line #L192 was not covered by tests
};

Ok(Block {
Expand Down
33 changes: 9 additions & 24 deletions biscuit-auth/src/token/authorizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,11 @@ impl Authorizer {
/// you can use this to save a set of policies and load them quickly before
/// verification. This will not store data obtained or generated from a token.
pub fn save(&self) -> Result<AuthorizerPolicies, error::Token> {
let facts = self
.authorizer_block_builder
.facts
.iter()
.cloned()
.collect();
let facts = self.authorizer_block_builder.facts.to_vec();

Check warning on line 187 in biscuit-auth/src/token/authorizer.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/token/authorizer.rs#L187

Added line #L187 was not covered by tests

let rules = self
.authorizer_block_builder
.rules
.iter()
.cloned()
.collect();
let rules = self.authorizer_block_builder.rules.to_vec();

Check warning on line 189 in biscuit-auth/src/token/authorizer.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/token/authorizer.rs#L189

Added line #L189 was not covered by tests

let checks = self
.authorizer_block_builder
.checks
.iter()
.cloned()
.collect();
let checks = self.authorizer_block_builder.checks.to_vec();

Check warning on line 191 in biscuit-auth/src/token/authorizer.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/token/authorizer.rs#L191

Added line #L191 was not covered by tests

Ok(AuthorizerPolicies {
version: crate::token::MAX_SCHEMA_VERSION,
Expand Down Expand Up @@ -829,7 +814,7 @@ impl Authorizer {
errors.push(error::FailedCheck::Block(error::FailedBlockCheck {
block_id: 0u32,
check_id: j as u32,
rule: self.symbols.print_check(&check),
rule: self.symbols.print_check(check),
}));
}
}
Expand Down Expand Up @@ -868,7 +853,7 @@ impl Authorizer {
}

if let Some(blocks) = self.blocks.as_ref() {
for (i, block) in (&blocks[1..]).iter().enumerate() {
for (i, block) in (blocks[1..]).iter().enumerate() {
let block_trusted_origins = TrustedOrigins::from_scopes(
&block.scopes,
&TrustedOrigins::default(),
Expand Down Expand Up @@ -922,7 +907,7 @@ impl Authorizer {
errors.push(error::FailedCheck::Block(error::FailedBlockCheck {
block_id: (i + 1) as u32,
check_id: j as u32,
rule: self.symbols.print_check(&check),
rule: self.symbols.print_check(check),
}));
}
}
Expand Down Expand Up @@ -992,21 +977,21 @@ impl Authorizer {
let _ = writeln!(f, "{fact};");
}
if !facts.is_empty() {
let _ = writeln!(f, "");
let _ = writeln!(f);
}

for rule in &rules {
let _ = writeln!(f, "{rule};");
}
if !rules.is_empty() {
let _ = writeln!(f, "");
let _ = writeln!(f);
}

for check in &checks {
let _ = writeln!(f, "{check};");
}
if !checks.is_empty() {
let _ = writeln!(f, "");
let _ = writeln!(f);
}

for policy in &policies {
Expand Down
2 changes: 1 addition & 1 deletion biscuit-auth/src/token/authorizer/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl super::Authorizer {
let policies = world
.authorizer_policies
.iter()
.map(|policy| proto_policy_to_policy(&policy, &symbols, version))
.map(|policy| proto_policy_to_policy(policy, &symbols, version))

Check warning on line 64 in biscuit-auth/src/token/authorizer/snapshot.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/token/authorizer/snapshot.rs#L64

Added line #L64 was not covered by tests
.collect::<Result<Vec<Policy>, error::Format>>()?;

let mut authorizer = super::Authorizer::new();
Expand Down
4 changes: 2 additions & 2 deletions biscuit-auth/src/token/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ impl Block {
})
.collect::<Result<Vec<Check>, error::Format>>()?,
context: self.context.clone(),
version: self.version.clone(),
external_key: self.external_key.clone(),
version: self.version,
external_key: self.external_key,
public_keys: self.public_keys.clone(),
scopes: self
.scopes
Expand Down
12 changes: 6 additions & 6 deletions biscuit-auth/src/token/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,22 @@ impl BlockBuilder {
facts: block
.facts
.iter()
.map(|f| Fact::convert_from(f, &symbols))
.map(|f| Fact::convert_from(f, symbols))

Check warning on line 234 in biscuit-auth/src/token/builder.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/token/builder.rs#L234

Added line #L234 was not covered by tests
.collect::<Result<Vec<Fact>, error::Format>>()?,
rules: block
.rules
.iter()
.map(|r| Rule::convert_from(r, &symbols))
.map(|r| Rule::convert_from(r, symbols))

Check warning on line 239 in biscuit-auth/src/token/builder.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/token/builder.rs#L239

Added line #L239 was not covered by tests
.collect::<Result<Vec<Rule>, error::Format>>()?,
checks: block
.checks
.iter()
.map(|c| Check::convert_from(c, &symbols))
.map(|c| Check::convert_from(c, symbols))

Check warning on line 244 in biscuit-auth/src/token/builder.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/token/builder.rs#L244

Added line #L244 was not covered by tests
.collect::<Result<Vec<Check>, error::Format>>()?,
scopes: block
.scopes
.iter()
.map(|s| Scope::convert_from(s, &symbols))
.map(|s| Scope::convert_from(s, symbols))

Check warning on line 249 in biscuit-auth/src/token/builder.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/token/builder.rs#L249

Added line #L249 was not covered by tests
.collect::<Result<Vec<Scope>, error::Format>>()?,
context: block.context.clone(),
})
Expand Down Expand Up @@ -1882,7 +1882,7 @@ impl From<i64> for Term {
#[cfg(feature = "datalog-macro")]
impl ToAnyParam for i64 {
fn to_any_param(&self) -> AnyParam {
AnyParam::Term((*self as i64).into())
AnyParam::Term((*self).into())

Check warning on line 1885 in biscuit-auth/src/token/builder.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-auth/src/token/builder.rs#L1885

Added line #L1885 was not covered by tests
}
}

Expand All @@ -1908,7 +1908,7 @@ impl From<bool> for Term {
#[cfg(feature = "datalog-macro")]
impl ToAnyParam for bool {
fn to_any_param(&self) -> AnyParam {
AnyParam::Term((*self as bool).into())
AnyParam::Term((*self).into())
}
}

Expand Down
10 changes: 5 additions & 5 deletions biscuit-auth/src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ fn print_block(symbols: &SymbolTable, block: &Block) -> String {
block.symbols.strings(),
block.version,
block.context.as_deref().unwrap_or(""),
block.external_key.as_ref().map(|k| hex::encode(k.to_bytes())).unwrap_or_else(String::new),
block.external_key.as_ref().map(|k| hex::encode(k.to_bytes())).unwrap_or_default(),
block.public_keys.keys.iter().map(|k | hex::encode(k.to_bytes())).collect::<Vec<_>>(),
block.scopes,
facts,
Expand Down Expand Up @@ -761,7 +761,7 @@ mod tests {
*/

let serialized2 = {
let biscuit1_deser = Biscuit::from(&serialized1, &root.public()).unwrap();
let biscuit1_deser = Biscuit::from(&serialized1, root.public()).unwrap();

// new check: can only have read access1
let mut block2 = BlockBuilder::new();
Expand Down Expand Up @@ -817,7 +817,7 @@ mod tests {
println!("generated biscuit token 3: {} bytes", serialized3.len());
//panic!();

let final_token = Biscuit::from(&serialized3, &root.public()).unwrap();
let final_token = Biscuit::from(&serialized3, root.public()).unwrap();
println!("final token:\n{}", final_token);
{
let mut authorizer = final_token.authorizer().unwrap();
Expand Down Expand Up @@ -1060,7 +1060,7 @@ mod tests {
let sealed = biscuit2.seal().unwrap().to_vec().unwrap();
//println!("biscuit2 sealed ({} bytes):\n{}", sealed.len(), sealed.to_hex(16));

let biscuit3 = Biscuit::from(&sealed, &root.public()).unwrap();
let biscuit3 = Biscuit::from(sealed, root.public()).unwrap();

{
let mut authorizer = biscuit3.authorizer().unwrap();
Expand Down Expand Up @@ -1427,7 +1427,7 @@ mod tests {
//println!("generated biscuit token 2: {} bytes\n{}", serialized2.len(), serialized2.to_hex(16));
println!("generated biscuit token 2: {} bytes", serialized2.len());

let final_token = Biscuit::from(&serialized2, &root.public()).unwrap();
let final_token = Biscuit::from(&serialized2, root.public()).unwrap();
println!("final token:\n{}", final_token);

let mut authorizer = final_token.authorizer().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions biscuit-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ fn scope(i: &str) -> IResult<&str, builder::Scope, Error> {
alt((
map(tag("authority"), |_| builder::Scope::Authority),
map(tag("previous"), |_| builder::Scope::Previous),
map(public_key, |bytes| builder::Scope::PublicKey(bytes)),
map(public_key, builder::Scope::PublicKey),
map(delimited(char('{'), name, char('}')), |n| {
builder::Scope::Parameter(n.to_string())
}),
Expand Down Expand Up @@ -739,7 +739,7 @@ fn parse_hex(i: &str) -> IResult<&str, Vec<u8>, Error> {
map_res(
take_while1(|c| {
let c = c as u8;
(b'0'..=b'9').contains(&c) || (b'a'..=b'f').contains(&c) || (b'A'..=b'F').contains(&c)
c.is_ascii_digit() || (b'a'..=b'f').contains(&c) || (b'A'..=b'F').contains(&c)
}),
hex::decode,
)(i)
Expand Down
8 changes: 4 additions & 4 deletions biscuit-quote/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ pub fn rule(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
// here. The block management happens only at compile-time, so it won't
// affect runtime performance.
let ty = syn::parse_quote!(::biscuit_auth::builder::BlockBuilder);
let builder = Builder::block_source(ty, None, &datalog, parameters)
let builder = Builder::block_source(ty, None, datalog, parameters)

Check warning on line 514 in biscuit-quote/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-quote/src/lib.rs#L514

Added line #L514 was not covered by tests
.unwrap_or_else(|e| abort_call_site!(e.to_string()));

let mut rule_item = if let Some(r) = builder.rules.first() {
Expand Down Expand Up @@ -579,7 +579,7 @@ pub fn fact(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
// here. The block management happens only at compile-time, so it won't
// affect runtime performance.
let ty = syn::parse_quote!(::biscuit_auth::builder::BlockBuilder);
let builder = Builder::block_source(ty, None, &datalog, parameters)
let builder = Builder::block_source(ty, None, datalog, parameters)

Check warning on line 582 in biscuit-quote/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-quote/src/lib.rs#L582

Added line #L582 was not covered by tests
.unwrap_or_else(|e| abort_call_site!(e.to_string()));

let mut fact_item = if let Some(f) = builder.facts.first() {
Expand Down Expand Up @@ -647,7 +647,7 @@ pub fn check(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
// here. The block management happens only at compile-time, so it won't
// affect runtime performance.
let ty = syn::parse_quote!(::biscuit_auth::builder::BlockBuilder);
let builder = Builder::block_source(ty, None, &datalog, parameters)
let builder = Builder::block_source(ty, None, datalog, parameters)

Check warning on line 650 in biscuit-quote/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-quote/src/lib.rs#L650

Added line #L650 was not covered by tests
.unwrap_or_else(|e| abort_call_site!(e.to_string()));

let mut check_item = if let Some(c) = builder.checks.first() {
Expand Down Expand Up @@ -715,7 +715,7 @@ pub fn policy(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
// here. The block management happens only at compile-time, so it won't
// affect runtime performance.
let ty = syn::parse_quote!(::biscuit_auth::Authorizer);
let builder = Builder::source(ty, None, &datalog, parameters)
let builder = Builder::source(ty, None, datalog, parameters)

Check warning on line 718 in biscuit-quote/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

biscuit-quote/src/lib.rs#L718

Added line #L718 was not covered by tests
.unwrap_or_else(|e| abort_call_site!(e.to_string()));

let mut policy_item = if let Some(p) = builder.policies.first() {
Expand Down

0 comments on commit 9043f42

Please sign in to comment.