From 500852f835a7a674170a0e4d4637e7d921281c74 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 13 Aug 2021 09:40:55 +1000 Subject: [PATCH 1/4] update dependencies for sha-1 and md-5 --- Cargo.toml | 13 ++++++------- src/v3.rs | 15 ++++++++------- src/v5.rs | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 472043a9..1ebf17f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,20 +55,20 @@ repository = "uuid-rs/uuid" optional = true version = "0.2.0" -[dependencies.md5] +[dependencies.md-5] default-features = false optional = true -version = "0.7" +version = "0.9" [dependencies.serde] default-features = false optional = true version = "1.0.56" -[dependencies.sha1] +[dependencies.sha-1] default-features = false optional = true -version = "0.6" +version = "0.9" [dependencies.slog] optional = true @@ -99,12 +99,11 @@ guid = ["winapi"] std = [] stdweb = ["getrandom", "getrandom/js"] v1 = [] -v3 = ["md5"] +v3 = ["md-5"] v4 = ["getrandom"] -v5 = ["sha1"] +v5 = ["sha-1"] wasm-bindgen = ["getrandom", "getrandom/js"] [target.'cfg(windows)'.dependencies.winapi] optional = true version = "0.3" - diff --git a/src/v3.rs b/src/v3.rs index f91decce..556b2ab3 100644 --- a/src/v3.rs +++ b/src/v3.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use md5; +use md5::{Md5, Digest}; impl Uuid { /// Creates a UUID using a name from a namespace, based on the MD5 @@ -20,16 +20,17 @@ impl Uuid { /// [`NAMESPACE_URL`]: #associatedconstant.NAMESPACE_URL /// [`NAMESPACE_X500`]: #associatedconstant.NAMESPACE_X500 pub fn new_v3(namespace: &Uuid, name: &[u8]) -> Uuid { - let mut context = md5::Context::new(); + let mut hasher = Md5::new(); - context.consume(namespace.as_bytes()); - context.consume(name); + hasher.update(namespace.as_bytes()); + hasher.update(name); - let computed = context.compute(); - let bytes = computed.into(); + let buffer = hasher.finalize(); - let mut builder = crate::Builder::from_bytes(bytes); + let mut bytes = crate::Bytes::default(); + bytes.copy_from_slice(&buffer[..16]); + let mut builder = crate::Builder::from_bytes(bytes); builder .set_variant(Variant::RFC4122) .set_version(Version::Md5); diff --git a/src/v5.rs b/src/v5.rs index fdd7e53e..c4816ba8 100644 --- a/src/v5.rs +++ b/src/v5.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use sha1; +use sha1::{Digest, Sha1}; impl Uuid { /// Creates a UUID using a name from a namespace, based on the SHA-1 hash. @@ -19,12 +19,12 @@ impl Uuid { /// [`NAMESPACE_URL`]: struct.Uuid.html#associatedconst.NAMESPACE_URL /// [`NAMESPACE_X500`]: struct.Uuid.html#associatedconst.NAMESPACE_X500 pub fn new_v5(namespace: &Uuid, name: &[u8]) -> Uuid { - let mut hash = sha1::Sha1::new(); + let mut hasher = Sha1::new(); - hash.update(namespace.as_bytes()); - hash.update(name); + hasher.update(namespace.as_bytes()); + hasher.update(name); - let buffer = hash.digest().bytes(); + let buffer = hasher.finalize(); let mut bytes = crate::Bytes::default(); bytes.copy_from_slice(&buffer[..16]); From acb21e774bd28aeb9f7c7b82a98c1bbfaa9ab462 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 13 Aug 2021 09:44:32 +1000 Subject: [PATCH 2/4] run fmt --- src/prelude.rs | 9 +++++---- src/v3.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/prelude.rs b/src/prelude.rs index ebacc1b3..7d269f39 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -32,15 +32,16 @@ //! [`Variant`]: ../enum.Variant.html //! [`Version`]: ../enum.Version.html //! [`Builder`]: ../builder/struct.Builder.html -//! -#![cfg_attr(feature = "v1", -doc = " +#![cfg_attr( + feature = "v1", + doc = " [`uuid::v1`]`::{`[`ClockSequence`],[`Context`]`}`: The types useful for handling uuid version 1. Requires feature `v1`. [`uuid::v1`]: ../v1/index.html [`Context`]: ../v1/struct.Context.html -[`ClockSequence`]: ../v1/trait.ClockSequence.html")] +[`ClockSequence`]: ../v1/trait.ClockSequence.html" +)] pub use super::{Builder, Bytes, Error, Uuid, Variant, Version}; #[cfg(feature = "v1")] diff --git a/src/v3.rs b/src/v3.rs index 556b2ab3..ca44d3ad 100644 --- a/src/v3.rs +++ b/src/v3.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use md5::{Md5, Digest}; +use md5::{Digest, Md5}; impl Uuid { /// Creates a UUID using a name from a namespace, based on the MD5 From f7643b619acd0856244f02994f68c69899e4c66d Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 13 Aug 2021 09:53:52 +1000 Subject: [PATCH 3/4] fix up clippy lints --- src/adapter/mod.rs | 2 +- src/builder/mod.rs | 8 ++++---- src/error.rs | 4 ++++ src/lib.rs | 5 ++++- src/parser/mod.rs | 32 ++++++++++++++++---------------- src/serde_support.rs | 2 +- src/slog_support.rs | 1 - src/v1.rs | 2 +- 8 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/adapter/mod.rs b/src/adapter/mod.rs index 4949c192..2cb682e3 100644 --- a/src/adapter/mod.rs +++ b/src/adapter/mod.rs @@ -816,7 +816,7 @@ impl<'a> UrnRef<'a> { /// [`Uuid`]: ../struct.Uuid.html /// [`UrnRef`]: struct.UrnRef.html pub const fn from_uuid_ref(uuid: &'a Uuid) -> Self { - UrnRef(&uuid) + UrnRef(uuid) } /// Writes the [`Uuid`] as a lower-case URN string to diff --git a/src/builder/mod.rs b/src/builder/mod.rs index a8c0c2d0..3cae1ea1 100644 --- a/src/builder/mod.rs +++ b/src/builder/mod.rs @@ -78,7 +78,7 @@ impl Uuid { let len = d4.len(); if len != D4_LEN { - Err(Error::new(D4_LEN, len))?; + return crate::err(Error::new(D4_LEN, len)); } Ok(Uuid::from_bytes([ @@ -135,7 +135,7 @@ impl Uuid { let len = d4.len(); if len != D4_LEN { - Err(Error::new(D4_LEN, len))?; + return crate::err(Error::new(D4_LEN, len)); } Ok(Uuid::from_bytes([ @@ -265,7 +265,7 @@ impl Uuid { let len = b.len(); if len != BYTES_LEN { - Err(Error::new(BYTES_LEN, len))?; + return crate::err(Error::new(BYTES_LEN, len)); } let mut bytes: Bytes = [0; 16]; @@ -372,7 +372,7 @@ impl crate::Builder { let len = b.len(); if len != BYTES_LEN { - Err(Error::new(BYTES_LEN, len))?; + return crate::err(Error::new(BYTES_LEN, len)); } let mut bytes: crate::Bytes = [0; 16]; diff --git a/src/error.rs b/src/error.rs index 433432b9..b48ed790 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,6 +7,10 @@ use crate::{builder, parser}; #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Error(Inner); +pub(crate) fn err(err: impl Into) -> Result { + Err(err.into()) +} + // TODO: write tests for Error // BODY: not immediately blocking, but should be covered for 1.0 #[derive(Clone, Debug, Eq, Hash, PartialEq)] diff --git a/src/lib.rs b/src/lib.rs index c561c9d8..d8581d7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -164,7 +164,10 @@ mod v5; #[cfg(all(windows, feature = "winapi"))] mod winapi_support; -use crate::std::{convert, fmt, str}; +use crate::{ + error::err, + std::{convert, fmt, str}, +}; pub use crate::error::Error; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 9243564b..9cc518a1 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -64,13 +64,13 @@ impl Uuid { len, &[adapter::Hyphenated::LENGTH, adapter::Simple::LENGTH], ) { - Err(Error::InvalidLength { + return crate::err(Error::InvalidLength { expected: error::ExpectedLength::Any(&[ adapter::Hyphenated::LENGTH, adapter::Simple::LENGTH, ]), found: len, - })?; + }); } // `digit` counts only hexadecimal digits, `i_char` counts all chars. @@ -82,19 +82,19 @@ impl Uuid { for (i_char, chr) in input.bytes().enumerate() { if digit as usize >= adapter::Simple::LENGTH && group != 4 { if group == 0 { - Err(Error::InvalidLength { + return crate::err(Error::InvalidLength { expected: error::ExpectedLength::Any(&[ adapter::Hyphenated::LENGTH, adapter::Simple::LENGTH, ]), found: len, - })?; + }); } - Err(Error::InvalidGroupCount { + return crate::err(Error::InvalidGroupCount { expected: error::ExpectedLength::Any(&[1, 5]), found: group + 1, - })?; + }); } if digit % 2 == 0 { @@ -121,13 +121,13 @@ impl Uuid { digit }; - Err(Error::InvalidGroupLength { + return crate::err(Error::InvalidGroupLength { expected: error::ExpectedLength::Exact( GROUP_LENS[group], ), found: found as usize, group, - })?; + }); } // Next group, decrement digit, it is incremented again // at the bottom. @@ -135,12 +135,12 @@ impl Uuid { digit -= 1; } _ => { - Err(Error::InvalidCharacter { + return crate::err(Error::InvalidCharacter { expected: "0123456789abcdefABCDEF-", found: input[i_char..].chars().next().unwrap(), index: i_char, urn: error::UrnPrefix::Optional, - })?; + }); } } } else { @@ -161,21 +161,21 @@ impl Uuid { digit }; - Err(Error::InvalidGroupLength { + return crate::err(Error::InvalidGroupLength { expected: error::ExpectedLength::Exact( GROUP_LENS[group], ), found: found as usize, group, - })?; + }); } _ => { - Err(Error::InvalidCharacter { + return crate::err(Error::InvalidCharacter { expected: "0123456789abcdefABCDEF-", found: input[i_char..].chars().next().unwrap(), index: i_char, urn: error::UrnPrefix::Optional, - })?; + }); } } buffer[(digit / 2) as usize] = acc; @@ -188,11 +188,11 @@ impl Uuid { // BODY: this only needed until we switch to // ParseError if ACC_GROUP_LENS[4] as u8 != digit { - Err(Error::InvalidGroupLength { + return crate::err(Error::InvalidGroupLength { expected: error::ExpectedLength::Exact(GROUP_LENS[4]), found: (digit as usize - ACC_GROUP_LENS[3]), group, - })?; + }); } Ok(Uuid::from_bytes(buffer)) diff --git a/src/serde_support.rs b/src/serde_support.rs index 096f24ed..b4a3ae08 100644 --- a/src/serde_support.rs +++ b/src/serde_support.rs @@ -20,7 +20,7 @@ impl Serialize for Uuid { ) -> Result { if serializer.is_human_readable() { serializer - .serialize_str(&self.to_hyphenated().encode_lower(&mut [0; 36])) + .serialize_str(self.to_hyphenated().encode_lower(&mut [0; 36])) } else { serializer.serialize_bytes(self.as_bytes()) } diff --git a/src/slog_support.rs b/src/slog_support.rs index 4046ae90..f03b709a 100644 --- a/src/slog_support.rs +++ b/src/slog_support.rs @@ -10,7 +10,6 @@ // except according to those terms. use crate::prelude::*; -use slog; impl slog::Value for Uuid { fn serialize( diff --git a/src/v1.rs b/src/v1.rs index 79429948..9a419ec3 100644 --- a/src/v1.rs +++ b/src/v1.rs @@ -196,7 +196,7 @@ impl Uuid { let len = node_id.len(); if len != NODE_ID_LEN { - Err(crate::builder::Error::new(NODE_ID_LEN, len))?; + return crate::err(crate::builder::Error::new(NODE_ID_LEN, len)); } let time_low = (ts.ticks & 0xFFFF_FFFF) as u32; From 5df3d797c2dcd92db9d74d4b0abed0315576e628 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 13 Aug 2021 10:03:43 +1000 Subject: [PATCH 4/4] just remove clippy from ci --- .github/workflows/clippy.yml | 41 ------------------------------------ .github/workflows/fmt.yml | 22 ------------------- 2 files changed, 63 deletions(-) delete mode 100644 .github/workflows/clippy.yml delete mode 100644 .github/workflows/fmt.yml diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml deleted file mode 100644 index 25072de8..00000000 --- a/.github/workflows/clippy.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Clippy - -on: [push, pull_request] - -jobs: - linux-clippy: - name: Linux - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v1 - - name: Install Toolchain - uses: actions-rs/toolchain@v1 - with: - components: clippy - override: true - profile: minimal - toolchain: 1.34.0 - - name: Run `cargo clippy` - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --features "serde slog std v1 v3 v4 v5" -- -D warnings - windows-clippy: - name: Windows - runs-on: windows-latest - steps: - - name: Checkout - uses: actions/checkout@v1 - - name: Install Toolchain - uses: actions-rs/toolchain@v1 - with: - components: clippy - override: true - profile: minimal - toolchain: 1.34.0 - - name: Run `cargo clippy` - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --features "guid serde slog std v1 v3 v4 v5" -- -D warnings diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml deleted file mode 100644 index fc0c6c55..00000000 --- a/.github/workflows/fmt.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Format Check - -on: [push, pull_request] - -jobs: - fmt: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v1 - - name: Install Toolchain - uses: actions-rs/toolchain@v1 - with: - components: rustfmt - override: true - profile: minimal - toolchain: 1.34.0 - - name: Run `cargo fmt` - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check