Skip to content

Commit

Permalink
Remove unsound lexical dependency (#392)
Browse files Browse the repository at this point in the history
* Remove unsound `lexical` dependency

* im so done
  • Loading branch information
aumetra authored Oct 27, 2023
1 parent fd7602d commit 6397a29
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions lib/masto-id-convert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ name = "process"
harness = false

[dependencies]
lexical = { version = "6.1.1", default-features = false, features = [
"parse-integers",
] }
atoi = { version = "2.0.0", default-features = false }
nanorand = { version = "0.7.0", default-features = false, features = [
"wyrand",
] }
Expand Down
18 changes: 8 additions & 10 deletions lib/masto-id-convert/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![warn(clippy::all, clippy::pedantic)]
#![cfg_attr(not(feature = "std"), no_std)]

use atoi::FromRadix10;
use core::fmt;
use nanorand::{Rng, WyRand};
use uuid::Uuid;
Expand All @@ -11,13 +12,7 @@ use uuid::Uuid;
#[derive(Debug)]
pub enum Error {
/// Number parsing error
Lexical(lexical::Error),
}

impl From<lexical::Error> for Error {
fn from(value: lexical::Error) -> Self {
Self::Lexical(value)
}
NumberParse,
}

impl fmt::Display for Error {
Expand Down Expand Up @@ -61,7 +56,10 @@ pub fn process<T>(masto_id: T) -> Result<Uuid, Error>
where
T: AsRef<[u8]>,
{
lexical::parse(masto_id)
.map(process_u64)
.map_err(Error::from)
let (result, index) = u64::from_radix_10(masto_id.as_ref());
if index == 0 {
return Err(Error::NumberParse);
}

Ok(process_u64(result))
}

0 comments on commit 6397a29

Please sign in to comment.