Repository: openwsn-berkeley/lakers (language: python)

Issue:
examples/coap: Update to new traits
This vastly enhances error handling.

This is still a PR because I think that EDHOCError should become renderable, so that EDHOC errors can fly out through `?`.


Discussion / hints:
Enhancing around the handling of EDHOCError is probably a more gradual thing, so I'm marking this as ready for review as it is (yes there are FIXMEs in the code, but those are still better than the panics that were in their place in the last iteration).

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 4586f037..0aa7b048 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,7 +2,6 @@
 
 members = [
   "lib",
-  "ead",
   "ead/lakers-ead-authz",
   "crypto",
   "crypto/lakers-crypto-psa",
@@ -18,7 +17,6 @@ members = [
 # tested on the host architecture
 default-members = [
   "lib",
-  "ead",
   "crypto",
   "crypto/lakers-crypto-rustcrypto",
   "examples/coap",
@@ -43,7 +41,6 @@ categories = [ "no-std::no-alloc", "network-programming", "embedded" ]
 
 lakers-shared = { package = "lakers-shared", path = "shared/", version = "^0.5.1" }
 
-lakers-ead = { package = "lakers-ead", path = "ead/", version = "^0.5.1", default-features = false }
 lakers-ead-authz = { package = "lakers-ead-authz", path = "ead/lakers-ead-authz/", version = "^0.5.1" }
 
 lakers-crypto = { path = "crypto/" }
diff --git a/ead/Cargo.toml b/ead/Cargo.toml
deleted file mode 100644
index 4292bcb7..00000000
--- a/ead/Cargo.toml
+++ /dev/null
@@ -1,19 +0,0 @@
-[package]
-name = "lakers-ead"
-version.workspace = true
-edition = "2021"
-authors = ["Geovane Fedrecheski <geonnave@gmail.com>"]
-license.workspace = true
-description = "EDHOC EAD library dispatch crate"
-repository.workspace = true
-readme.workspace = true
-
-[dependencies]
-lakers-shared.workspace = true
-
-lakers-ead-authz = { workspace = true, optional = true }
-
-[features]
-default = [ "ead-none" ]
-ead-none = [  ]
-ead-authz = [ "lakers-ead-authz" ]
diff --git a/ead/src/lib.rs b/ead/src/lib.rs
deleted file mode 100644
index 8e9fb12b..00000000
--- a/ead/src/lib.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-#![no_std]
-
-#[cfg(feature = "ead-authz")]
-pub use lakers_ead_authz::*;
diff --git a/examples/coap/Cargo.toml b/examples/coap/Cargo.toml
index 155b6144..734a1298 100644
--- a/examples/coap/Cargo.toml
+++ b/examples/coap/Cargo.toml
@@ -5,7 +5,7 @@ edition = "2021"
 
 [dependencies]
 lakers = { package = "lakers", path = "../../lib" }
-lakers-ead = { path = "../../ead/", features = [ "ead-authz" ] }
+lakers-ead-authz = { path = "../../ead/lakers-ead-authz" }
 lakers-crypto = { path = "../../crypto/", features = [ "rustcrypto" ] }
 hexlit = "0.5.3"
 coap = { version = "0.13" }
diff --git a/examples/coap/src/bin/coapserver-coaphandler.rs b/examples/coap/src/bin/coapserver-coaphandler.rs
index 30e42dc1..65641a01 100644
--- a/examples/coap/src/bin/coapserver-coaphandler.rs
+++ b/examples/coap/src/bin/coapserver-coaphandler.rs
@@ -1,7 +1,7 @@
 use hexlit::hex;
 use lakers::*;
 use lakers_crypto::Crypto;
-use lakers_ead::{ZeroTouchAuthenticator, ZeroTouchServer};
+use lakers_ead_authz::{ZeroTouchAuthenticator, ZeroTouchServer};
 
 use coap_message::{Code, MinimalWritableMessage, MutableWritableMessage, ReadableMessage};
 use coap_message_utils::{Error, OptionsExt as _};
diff --git a/examples/coap/src/bin/coapserver.rs b/examples/coap/src/bin/coapserver.rs
index 8a7060f0..a058ff0a 100644
--- a/examples/coap/src/bin/coapserver.rs
+++ b/examples/coap/src/bin/coapserver.rs
@@ -1,7 +1,7 @@
 use coap_lite::{CoapRequest, Packet, ResponseType};
 use hexlit::hex;
 use lakers::*;
-use lakers_ead::*;
+use lakers_ead_authz::{ZeroTouchAuthenticator, ZeroTouchServer};
 use std::net::UdpSocket;
 
 const ID_CRED_I: &[u8] = &hex!("a104412b");
diff --git a/examples/lakers-no_std/Cargo.toml b/examples/lakers-no_std/Cargo.toml
index d6e78c46..f5ad109d 100644
--- a/examples/lakers-no_std/Cargo.toml
+++ b/examples/lakers-no_std/Cargo.toml
@@ -6,7 +6,7 @@ edition = "2021"
 
 [dependencies]
 lakers = { package = "lakers", path = "../../lib", default-features = false }
-lakers-ead = { path = "../../ead/" }
+lakers-ead-authz = { path = "../../ead/lakers-ead-authz", optional = true }
 lakers-crypto = { path = "../../crypto", default-features = false }
 hexlit = "0.5.3"
 
@@ -26,5 +26,5 @@ default = [ "rtt", "crypto-cryptocell310", "ead-none" ]
 rtt = [ ]
 crypto-psa = [ "lakers-crypto/psa-baremetal" ]
 crypto-cryptocell310 = [ "lakers-crypto/cryptocell310" ]
-ead-none = [ "lakers-ead/ead-none" ]
-ead-authz = [ "lakers-ead/ead-authz" ]
+ead-none = [ ]
+ead-authz = [ "lakers-ead-authz" ]
diff --git a/lakers-c/Cargo.toml b/lakers-c/Cargo.toml
index dfba405b..827fe5d0 100644
--- a/lakers-c/Cargo.toml
+++ b/lakers-c/Cargo.toml
@@ -10,7 +10,7 @@ readme.workspace = true
 
 [dependencies]
 lakers = { package = "lakers", path = "../lib", default-features = false }
-lakers-ead = { path = "../ead/" }
+lakers-ead-authz = { path = "../ead/lakers-ead-authz", optional = true }
 lakers-crypto = { path = "../crypto", default-features = false }
 hexlit = "0.5.3"
 
@@ -27,8 +27,8 @@ crypto-rustcrypto = [ "lakers-crypto/rustcrypto", "critical-section" ]
 crypto-psa = [ "lakers-crypto/psa", "critical-section" ]
 crypto-psa-baremetal = [ "lakers-crypto/psa-baremetal" ]
 crypto-cryptocell310 = [ "lakers-crypto/cryptocell310" ]
-ead-none = [ "lakers-ead/ead-none" ]
-ead-authz = [ "lakers-ead/ead-authz" ]
+ead-none = [ ]
+ead-authz = [ "lakers-ead-authz" ]
 
 [lib]
 crate-type = ["staticlib"]
diff --git a/lakers-c/src/ead_authz.rs b/lakers-c/src/ead_authz.rs
index 14babae1..85feae2b 100644
--- a/lakers-c/src/ead_authz.rs
+++ b/lakers-c/src/ead_authz.rs
@@ -1,7 +1,7 @@
 use crate::*;
 use core::slice;
 use lakers_crypto::default_crypto;
-use lakers_ead::*;
+use lakers_ead_authz::*;
 
 #[derive(Debug)]
 #[repr(C)]
diff --git a/lakers-python/Cargo.toml b/lakers-python/Cargo.toml
index 623a729e..1c60f902 100644
--- a/lakers-python/Cargo.toml
+++ b/lakers-python/Cargo.toml
@@ -10,7 +10,7 @@ license.workspace = true
 [dependencies]
 pyo3 = { version = "0.20.2", features = ["extension-module"] }
 lakers = { package = "lakers", path = "../lib", default-features = false }
-lakers-ead = { path = "../ead/", features = [ "ead-authz" ] }
+lakers-ead-authz = { path = "../ead/lakers-ead-authz" }
 lakers-shared = { path = "../shared", features = ["python-bindings"] }
 lakers-crypto = { path = "../crypto", default-features = false, features = ["rustcrypto"] }
 
diff --git a/lakers-python/src/ead_authz/authenticator.rs b/lakers-python/src/ead_authz/authenticator.rs
index da60e349..ff0dc907 100644
--- a/lakers-python/src/ead_authz/authenticator.rs
+++ b/lakers-python/src/ead_authz/authenticator.rs
@@ -1,5 +1,5 @@
 use lakers::*;
-use lakers_ead::*;
+use lakers_ead_authz::*;
 use pyo3::{
     prelude::*,
     types::{PyBytes, PyString},
diff --git a/lakers-python/src/ead_authz/device.rs b/lakers-python/src/ead_authz/device.rs
index ee50732c..5cfbd6cc 100644
--- a/lakers-python/src/ead_authz/device.rs
+++ b/lakers-python/src/ead_authz/device.rs
@@ -1,6 +1,6 @@
 use lakers::*;
 use lakers_crypto::default_crypto;
-use lakers_ead::*;
+use lakers_ead_authz::*;
 use pyo3::{exceptions::PyBaseException, prelude::*, types::PyBytes};
 
 #[pyclass(name = "AuthzDevice")]
diff --git a/lakers-python/src/ead_authz/server.rs b/lakers-python/src/ead_authz/server.rs
index 9d549a08..3815a1eb 100644
--- a/lakers-python/src/ead_authz/server.rs
+++ b/lakers-python/src/ead_authz/server.rs
@@ -1,6 +1,6 @@
 use lakers::*;
 use lakers_crypto::default_crypto;
-use lakers_ead::*;
+use lakers_ead_authz::*;
 use pyo3::{prelude::*, types::PyBytes};
 
 #[pyclass(name = "AuthzEnrollmentServer")]
diff --git a/lakers-python/src/lib.rs b/lakers-python/src/lib.rs
index ee7e0b9b..83ad6ef4 100644
--- a/lakers-python/src/lib.rs
+++ b/lakers-python/src/lib.rs
@@ -1,7 +1,7 @@
 /// This file implements the python bindings for the lakers library.
 /// Note that this module is not restricted by no_std.
 use lakers::*;
-// use lakers_ead::consts::*;
+// use lakers_ead_authz::consts::*;
 use lakers_crypto::{default_crypto, CryptoTrait};
 use pyo3::wrap_pyfunction;
 use pyo3::{prelude::*, types::PyBytes};
@@ -77,7 +77,7 @@ fn lakers_python(_py: Python, m: &PyModule) -> PyResult<()> {
     m.add_class::<ead_authz::PyAuthzServerUserAcl>()?;
 
     let submodule = PyModule::new(_py, "consts")?;
-    submodule.add("EAD_AUTHZ_LABEL", lakers_ead::consts::EAD_AUTHZ_LABEL)?;
+    submodule.add("EAD_AUTHZ_LABEL", lakers_ead_authz::consts::EAD_AUTHZ_LABEL)?;
     m.add_submodule(submodule)?;
     Ok(())
 }
diff --git a/lib/Cargo.toml b/lib/Cargo.toml
index e24d5d1d..d48a6134 100644
--- a/lib/Cargo.toml
+++ b/lib/Cargo.toml
@@ -13,15 +13,15 @@ categories.workspace = true
 lakers-shared.workspace = true
 
 [dev-dependencies]
-lakers-ead = { workspace = true, default-features = false }
+lakers-ead-authz = { workspace = true }
 lakers-crypto.workspace = true
 hexlit = "0.5.3"
 
 [features]
 # NOTE: the ead features are just needed for multiplexing tests
 default = [ "test-ead-none" ]
-test-ead-none = [ "lakers-ead/ead-none" ]
-test-ead-authz = [ "lakers-ead/ead-authz" ]
+test-ead-none = [ ]
+test-ead-authz = [ ]
 
 [lib]
 crate-type = ["rlib"]
diff --git a/lib/src/lib.rs b/lib/src/lib.rs
index 8285dab8..20859a7a 100644
--- a/lib/src/lib.rs
+++ b/lib/src/lib.rs
@@ -17,8 +17,8 @@
 
 pub use {lakers_shared::Crypto as CryptoTrait, lakers_shared::*};
 
-#[cfg(any(feature = "ead-none", feature = "ead-authz"))]
-pub use lakers_ead::*;
+#[cfg(all(feature = "ead-authz", test))]
+pub use lakers_ead_authz::*;
 
 mod edhoc;
 pub use edhoc::*;
@@ -624,7 +624,7 @@ mod test_authz {
     use super::*;
     use hexlit::hex;
     use lakers_crypto::default_crypto;
-    use lakers_ead::*;
+    use lakers_ead_authz::*;
     use test_vectors_common::*;
 
     // U


Test patch:
diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml
index 7e9bada7..335ebd84 100644
--- a/.github/workflows/build-and-test.yml
+++ b/.github/workflows/build-and-test.yml
@@ -62,7 +62,6 @@ jobs:
       fail-fast: false
       matrix:
         crypto_backend: [lakers-crypto/psa, lakers-crypto/psa-baremetal, lakers-crypto/cryptocell310, lakers-crypto/rustcrypto]
-        ead: [lakers-ead/ead-none, lakers-ead/ead-authz]
 
     steps:
     - name: Checkout repo
@@ -74,7 +73,7 @@ jobs:
       run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi
 
     - name: Build
-      run: cargo build --package lakers --package lakers-crypto --package lakers-ead --no-default-features --features="${{ matrix.crypto_backend }}, ${{ matrix.ead }}" --release
+      run: cargo build --package lakers --package lakers-crypto --package lakers-ead-authz --no-default-features --features="${{ matrix.crypto_backend }}" --release
 
 
   generate-fstar:
@@ -90,7 +89,7 @@ jobs:
         cd lakers
 
         # generate the fstar files
-        cargo-hax -C -p lakers --no-default-features --features='lakers-crypto/rustcrypto, lakers-ead/ead-none' --release \; into -i '-lakers::generate_connection_identifier_cbor -lakers::generate_connection_identifier' fstar
+        cargo-hax -C -p lakers --no-default-features --features='lakers-crypto/rustcrypto' --release \; into -i '-lakers::generate_connection_identifier_cbor -lakers::generate_connection_identifier' fstar
         cargo-hax -C -p lakers-shared \; into -i '-lakers_shared::ffi::**' fstar
 
         # even if fstar generation was ok, fail if something is not implemented
@@ -167,7 +166,6 @@ jobs:
       fail-fast: false
       matrix:
         crypto_backend: [crypto-psa]
-        ead: [lakers-ead/ead-none, lakers-ead/ead-authz]
 
     steps:
     - name: Checkout repo
@@ -181,7 +179,7 @@ jobs:
       run: sudo apt-get -y install qemu-system-arm
 
     - name: Run tests in QEMU
-      run: cd examples/lakers-no_std && cargo run --target="thumbv7m-none-eabi" --no-default-features --features="${{ matrix.crypto_backend }}, ${{ matrix.ead }}" --release
+      run: cd examples/lakers-no_std && cargo run --target="thumbv7m-none-eabi" --no-default-features --features="${{ matrix.crypto_backend }}" --release
 
 
   build-example-for-cortex-m4:
@@ -192,7 +190,6 @@ jobs:
       fail-fast: false
       matrix:
         crypto_backend: [crypto-psa, crypto-cryptocell310]
-        ead: [lakers-ead/ead-none, lakers-ead/ead-authz]
 
     steps:
     - name: Checkout repo
@@ -204,7 +201,7 @@ jobs:
       run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi
 
     - name: Build example
-      run: cd examples/lakers-no_std && cargo build --target="thumbv7em-none-eabihf" --no-default-features --features="${{ matrix.crypto_backend }}, ${{ matrix.ead }}, rtt" --release
+      run: cd examples/lakers-no_std && cargo build --target="thumbv7em-none-eabihf" --no-default-features --features="${{ matrix.crypto_backend }}, rtt" --release
 
 
   build-coap-example: