diff --git a/.github/workflows/build-tlv-tool.yml b/.github/workflows/build-tlv-tool.yml deleted file mode 100644 index a28b303..0000000 --- a/.github/workflows/build-tlv-tool.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Build-TLV-Tool - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Build - run: cd tools/tlv; cargo build - - name: Archive artifacts - uses: actions/upload-artifact@v2 - with: - name: tlv - path: tools/tlv/target/debug/tlv diff --git a/.github/workflows/ci-tlv-tool.yml b/.github/workflows/ci-tlv-tool.yml new file mode 100644 index 0000000..fbe3a68 --- /dev/null +++ b/.github/workflows/ci-tlv-tool.yml @@ -0,0 +1,39 @@ +name: CITLVTool + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + schedule: + - cron: "20 7 * * *" + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + build_tlv_tool: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Fmt + run: cargo fmt -- --check + working-directory: tools/tlv + + - name: Clippy + run: cargo clippy --no-deps -- -Dwarnings + working-directory: tools/tlv + + - name: Build + run: cargo build + working-directory: tools/tlv + + - name: Archive artifacts + uses: actions/upload-artifact@v2 + with: + name: tlv + path: tools/tlv/target/debug/tlv diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..57a9ce9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + schedule: + - cron: "50 6 * * *" + workflow_dispatch: + +env: + RUST_TOOLCHAIN: nightly-2023-07-01 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CARGO_TERM_COLOR: always + +jobs: + build_and_test: + runs-on: ubuntu-latest + strategy: + matrix: + crypto-backend: ['rustcrypto', 'mbedtls', 'openssl'] + features: ['', 'alloc', 'os'] + toolchain: ['stable', 'nightly'] + + steps: + - name: Rust + if: matrix.toolchain == 'nightly' + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ env.RUST_TOOLCHAIN }} + components: rustfmt, clippy, rust-src + + - name: Checkout + uses: actions/checkout@v3 + + - name: Fmt + run: cargo +${{ matrix.toolchain == 'nightly' && env.RUST_TOOLCHAIN || 'stable'}} fmt -- --check + + - name: Clippy + run: cargo +${{ matrix.toolchain == 'nightly' && env.RUST_TOOLCHAIN || 'stable'}} clippy --no-deps --no-default-features --features ${{matrix.crypto-backend}},${{matrix.features}},${{ matrix.toolchain == 'nightly' && 'nightly' || ''}} -- -Dwarnings + + - name: Build + run: cargo +${{ matrix.toolchain == 'nightly' && env.RUST_TOOLCHAIN || 'stable'}} build --no-default-features --features ${{matrix.crypto-backend}},${{matrix.features}},${{ matrix.toolchain == 'nightly' && 'nightly' || ''}} + + - name: Test + if: matrix.features == 'os' + run: cargo +${{ matrix.toolchain == 'nightly' && env.RUST_TOOLCHAIN || 'stable'}} test --no-default-features --features ${{matrix.crypto-backend}},${{matrix.features}},${{ matrix.toolchain == 'nightly' && 'nightly' || ''}} -- --test-threads=1 diff --git a/.github/workflows/publish-dry-run.yml b/.github/workflows/publish-dry-run.yml new file mode 100644 index 0000000..14901a7 --- /dev/null +++ b/.github/workflows/publish-dry-run.yml @@ -0,0 +1,17 @@ +name: PublishDryRun + +on: workflow_dispatch + +env: + CRATE_NAME: rs-matter + +jobs: + publish_dry_run: + name: PublishDryRun + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: PublishDryRun + run: cargo publish -p rs-matter --dry-run diff --git a/.github/workflows/publish-macros-dry-run.yml b/.github/workflows/publish-macros-dry-run.yml new file mode 100644 index 0000000..ec23da7 --- /dev/null +++ b/.github/workflows/publish-macros-dry-run.yml @@ -0,0 +1,14 @@ +name: PublishMacrosDryRun + +on: workflow_dispatch + +jobs: + publish_macros_dry_run: + name: PublishMacrosDryRun + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: PublishDryRun-Macros + run: cargo publish -p rs-matter-macros --dry-run diff --git a/.github/workflows/publish-macros.yml b/.github/workflows/publish-macros.yml new file mode 100644 index 0000000..9ba9701 --- /dev/null +++ b/.github/workflows/publish-macros.yml @@ -0,0 +1,17 @@ +name: PublishMacros + +on: workflow_dispatch + +jobs: + publish_macros: + name: PublishMacros + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Login + run: cargo login ${{ secrets.CRATES_IO_TOKEN }} + + - name: Publish-Macros + run: cargo publish -p rs-matter-macros diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..a8b09ee --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,32 @@ +name: Publish + +on: workflow_dispatch + +env: + CRATE_NAME: rs-matter + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Login + run: cargo login ${{ secrets.CRATES_IO_TOKEN }} + + - name: Publish + run: cargo publish -p rs-matter + + - name: Get the crate version from cargo + run: | + version=$(cd rs-matter; cargo metadata --format-version=1 --no-deps | jq -r ".packages[] | select(.name == \"${{env.CRATE_NAME}}\") | .version") + echo "crate_version=$version" >> $GITHUB_ENV + echo "${{env.CRATE_NAME}} version: $version" + + - name: Tag the new release + uses: rickstaa/action-create-tag@v1 + with: + tag: v${{env.crate_version}} + message: "Release v${{env.crate_version}}" diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml deleted file mode 100644 index 1312812..0000000 --- a/.github/workflows/test-linux.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Test-Linux - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -env: - CARGO_TERM_COLOR: always - -jobs: - build_and_test: - - runs-on: ubuntu-latest - strategy: - matrix: - crypto-backend: ['rustcrypto', 'mbedtls', 'openssl'] - - steps: - - uses: actions/checkout@v2 - - name: Build - run: cd rs-matter; cargo build --no-default-features --features ${{matrix.crypto-backend}} - - name: Run tests - run: cd rs-matter; cargo test --no-default-features --features os,${{matrix.crypto-backend}} -- --test-threads=1 diff --git a/README.md b/README.md index 00cd23c..7a3dad3 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # rs-matter: The Rust Implementation of Matter -![experimental](https://img.shields.io/badge/status-Experimental-red) [![license](https://img.shields.io/badge/license-Apache2-green.svg)](https://raw.githubusercontent.com/project-chip/matter-rs/main/LICENSE) - -[![Test Linux (OpenSSL)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-openssl.yml/badge.svg)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-openssl.yml) -[![Test Linux (mbedTLS)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-mbedtls.yml/badge.svg)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-mbedtls.yml) +![experimental](https://img.shields.io/badge/status-Experimental-red) +[![license](https://img.shields.io/badge/license-Apache2-green.svg)](https://raw.githubusercontent.com/project-chip/matter-rs/main/LICENSE) +[![CI](https://github.com/project-chip/matter-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/project-chip/matter-rs/actions/workflows/ci.yml) +[![CI - TLV](https://github.com/project-chip/matter-rs/actions/workflows/ci-tlv-tool.yml/badge.svg)](https://github.com/project-chip/matter-rs/actions/workflows/ci-tlv-tool.yml) +[![crates.io](https://img.shields.io/crates/v/rs-matter.svg)](https://crates.io/crates/rs-matter) +[![Matrix](https://img.shields.io/matrix/matter-rs:matrix.org?label=join%20matrix&color=BEC5C9&logo=matrix)](https://matrix.to/#/#matter-rs:matrix.org) ## Build diff --git a/examples/onoff_light/src/main.rs b/examples/onoff_light/src/main.rs index 121f565..053370a 100644 --- a/examples/onoff_light/src/main.rs +++ b/examples/onoff_light/src/main.rs @@ -133,7 +133,7 @@ fn run() -> Result<(), Error> { let mut mdns_runner = pin!(mdns.run(&stack, &mut mdns_buffers)); let mut buffers = RunBuffers::new(); - let mut runner = matter.run( + let runner = matter.run( &stack, &mut buffers, CommissioningData { @@ -157,10 +157,10 @@ fn run() -> Result<(), Error> { #[cfg(not(all(feature = "std", not(target_os = "espidf"))))] let mut psm_runner = pin!(core::future::pending()); - let mut runner = select3(&mut runner, &mut mdns_runner, &mut psm_runner); + let runner = select3(&mut runner, &mut mdns_runner, &mut psm_runner); #[cfg(feature = "std")] - async_io::block_on(&mut runner).unwrap()?; + async_io::block_on(runner).unwrap()?; // NOTE (no_std): For no_std, replace with your own more efficient no_std executor, // because the executor used below is a simple busy-loop poller diff --git a/rs-matter-macros/Cargo.toml b/rs-matter-macros/Cargo.toml index 9bf4e7d..9bfd422 100644 --- a/rs-matter-macros/Cargo.toml +++ b/rs-matter-macros/Cargo.toml @@ -2,6 +2,12 @@ name = "rs-matter-macros" version = "0.1.0" edition = "2021" +authors = ["Kedar Sovani "] +description = "Native Rust implementation of the Matter (Smart-Home) ecosystem - Proc-macros" +repository = "https://github.com/project-chip/matter-rs" +readme = "README.md" +keywords = ["matter", "smart", "smart-home", "IoT", "ESP32"] +categories = ["embedded", "network-programming"] license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/rs-matter-macros/README.md b/rs-matter-macros/README.md index e973784..faf5fb0 100644 --- a/rs-matter-macros/README.md +++ b/rs-matter-macros/README.md @@ -1,4 +1,4 @@ -# rs-matter-macros +# rs-matter-macros: The Rust Implementation of Matter Library - Proc-macros Proc-macros for implementing the `ToTLV` and `FromTLV` traits. diff --git a/rs-matter/Cargo.toml b/rs-matter/Cargo.toml index f08d06c..3902a6f 100644 --- a/rs-matter/Cargo.toml +++ b/rs-matter/Cargo.toml @@ -3,17 +3,13 @@ name = "rs-matter" version = "0.1.0" edition = "2021" authors = ["Kedar Sovani "] -description = "Native RUST implementation of the Matter (Smart-Home) ecosystem" -repository = "https://github.com/kedars/matter-rs" +description = "Native Rust implementation of the Matter (Smart-Home) ecosystem" +repository = "https://github.com/project-chip/matter-rs" readme = "README.md" keywords = ["matter", "smart", "smart-home", "IoT", "ESP32"] categories = ["embedded", "network-programming"] license = "Apache-2.0" -[lib] -name = "rs_matter" -path = "src/lib.rs" - [features] default = ["os", "mbedtls"] os = ["std", "backtrace", "env_logger", "nix", "critical-section/std", "embassy-sync/std", "embassy-time/std"] @@ -28,7 +24,7 @@ rustcrypto = ["alloc", "sha2", "hmac", "pbkdf2", "hkdf", "aes", "ccm", "p256", " embassy-net = ["dep:embassy-net", "dep:embassy-net-driver", "smoltcp"] [dependencies] -rs-matter-macros = { path = "../rs-matter-macros" } +rs-matter-macros = { version = "0.1", path = "../rs-matter-macros" } bitflags = { version = "1.3", default-features = false } byteorder = { version = "1.4.3", default-features = false } heapless = "0.7.16" diff --git a/rs-matter/src/crypto/crypto_openssl.rs b/rs-matter/src/crypto/crypto_openssl.rs index a29df5c..3185e37 100644 --- a/rs-matter/src/crypto/crypto_openssl.rs +++ b/rs-matter/src/crypto/crypto_openssl.rs @@ -59,7 +59,8 @@ impl HmacSha256 { } pub fn update(&mut self, data: &[u8]) -> Result<(), Error> { - Ok(self.ctx.update(data)) + self.ctx.update(data); + Ok(()) } pub fn finish(self, out: &mut [u8]) -> Result<(), Error> { @@ -118,7 +119,7 @@ impl KeyPair { fn private_key(&self) -> Result<&EcKey, Error> { match &self.key { KeyType::Public(_) => Err(ErrorCode::Invalid.into()), - KeyType::Private(k) => Ok(&k), + KeyType::Private(k) => Ok(k), } } @@ -227,7 +228,7 @@ impl KeyPair { } const P256_KEY_LEN: usize = 256 / 8; -pub fn pubkey_from_der<'a>(der: &'a [u8], out_key: &mut [u8]) -> Result<(), Error> { +pub fn pubkey_from_der(der: &[u8], out_key: &mut [u8]) -> Result<(), Error> { if out_key.len() != P256_KEY_LEN { error!("Insufficient length"); Err(ErrorCode::NoSpace.into()) @@ -286,7 +287,7 @@ pub fn decrypt_in_place( ) -> Result { let tag_start = data.len() - super::AEAD_MIC_LEN_BYTES; let (data, tag) = data.split_at_mut(tag_start); - let result = lowlevel_decrypt_aead(key, Some(nonce), ad, data, &tag)?; + let result = lowlevel_decrypt_aead(key, Some(nonce), ad, data, tag)?; data[..result.len()].copy_from_slice(result.as_slice()); Ok(result.len()) } diff --git a/rs-matter/src/data_model/objects/attribute.rs b/rs-matter/src/data_model/objects/attribute.rs index 69fd544..f22eb33 100644 --- a/rs-matter/src/data_model/objects/attribute.rs +++ b/rs-matter/src/data_model/objects/attribute.rs @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#![allow(clippy::bad_bit_mask)] use crate::data_model::objects::GlobalElements; diff --git a/rs-matter/src/data_model/objects/encoder.rs b/rs-matter/src/data_model/objects/encoder.rs index 73f610b..f3433a8 100644 --- a/rs-matter/src/data_model/objects/encoder.rs +++ b/rs-matter/src/data_model/objects/encoder.rs @@ -141,7 +141,7 @@ impl<'a, 'b, 'c> AttrDataEncoder<'a, 'b, 'c> { #[cfg(feature = "nightly")] { - handler.read(&attr, encoder).await + handler.read(attr, encoder).await } }; @@ -181,9 +181,7 @@ impl<'a, 'b, 'c> AttrDataEncoder<'a, 'b, 'c> { #[cfg(feature = "nightly")] { - handler - .write(&attr, AttrData::new(attr.dataver, &data)) - .await + handler.write(attr, AttrData::new(attr.dataver, data)).await } }; @@ -357,7 +355,7 @@ impl<'a, 'b, 'c> CmdDataEncoder<'a, 'b, 'c> { #[cfg(feature = "nightly")] { - handler.invoke(exchange, &cmd, &data, encoder).await + handler.invoke(exchange, cmd, data, encoder).await } }; diff --git a/rs-matter/src/interaction_model/core.rs b/rs-matter/src/interaction_model/core.rs index b2d3b8c..cd778c0 100644 --- a/rs-matter/src/interaction_model/core.rs +++ b/rs-matter/src/interaction_model/core.rs @@ -632,7 +632,7 @@ impl<'a, 'r, 'p> Interaction<'a, 'r, 'p> { #[inline(always)] pub fn new( exchange: &'r mut Exchange<'a>, - rx: &'r mut Packet<'p>, + rx: &'r Packet<'p>, tx: &'r mut Packet<'p>, rx_status: &'r mut Packet<'p>, subscription_id: S, diff --git a/rs-matter/src/secure_channel/case.rs b/rs-matter/src/secure_channel/case.rs index 28f4508..84da032 100644 --- a/rs-matter/src/secure_channel/case.rs +++ b/rs-matter/src/secure_channel/case.rs @@ -485,7 +485,7 @@ impl<'a> Case<'a> { fn get_sigma2_key( ipk: &[u8], our_random: &[u8], - case_session: &mut CaseSession, + case_session: &CaseSession, key: &mut [u8], ) -> Result<(), Error> { const S2K_INFO: [u8; 6] = [0x53, 0x69, 0x67, 0x6d, 0x61, 0x32]; diff --git a/rs-matter/src/secure_channel/crypto_openssl.rs b/rs-matter/src/secure_channel/crypto_openssl.rs index dd4f8b1..4254e6f 100644 --- a/rs-matter/src/secure_channel/crypto_openssl.rs +++ b/rs-matter/src/secure_channel/crypto_openssl.rs @@ -235,7 +235,7 @@ impl CryptoSpake2 { let mut len_buf: [u8; 8] = [0; 8]; LittleEndian::write_u64(&mut len_buf, buf.len() as u64); tt.update(&len_buf)?; - if buf.len() > 0 { + if !buf.is_empty() { tt.update(buf)?; } Ok(()) @@ -263,6 +263,7 @@ impl CryptoSpake2 { #[inline(always)] #[allow(non_snake_case)] #[allow(dead_code)] + #[allow(clippy::too_many_arguments)] fn get_ZV_as_prover( w0: &BigNum, w1: &BigNum, @@ -298,6 +299,7 @@ impl CryptoSpake2 { #[inline(always)] #[allow(non_snake_case)] #[allow(dead_code)] + #[allow(clippy::too_many_arguments)] fn get_ZV_as_verifier( w0: &BigNum, L: &EcPoint,