diff --git a/common/Cargo.lock b/common/Cargo.lock index 586e64e..7e6c365 100644 --- a/common/Cargo.lock +++ b/common/Cargo.lock @@ -2,13 +2,77 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "common" version = "0.1.0" dependencies = [ "serde", + "sha3", ] +[[package]] +name = "cpufeatures" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "libc" +version = "0.2.167" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" + [[package]] name = "proc-macro2" version = "1.0.92" @@ -47,6 +111,16 @@ dependencies = [ "syn", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "syn" version = "2.0.90" @@ -58,8 +132,20 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" diff --git a/common/Cargo.toml b/common/Cargo.toml index 81e97a8..a1f73e8 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -4,4 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] +sha3 = {version="0.10.0", default-features=false} serde = { version = "1.0.203", default-features = false, features = ["derive"] } diff --git a/common/src/lib.rs b/common/src/lib.rs index 123e34f..db2d4b9 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,6 +1,7 @@ #![no_std] use serde::Deserialize; use serde::Serialize; +use sha3::{Digest, Sha3_256}; #[derive(Serialize, Deserialize, Debug)] pub enum Request { @@ -25,7 +26,24 @@ pub enum Name { Thia, Michael, Zoey, - Coke, Unknown, } +impl Name { + pub fn from_badge(badge: u64) -> Self { + let mut hasher = Sha3_256::new(); + hasher.update(badge.to_be_bytes()); + + let hash = hasher.finalize(); + let hash = u64::from_be_bytes(hash[..8].try_into().unwrap()); + + match hash { + 0x14b9c91fe4505456 => Self::Evan, + 0x6b859025842cd369 => Self::Andy, + 0xb366d73deaaa8d9d => Self::Felix, + 0x30c79f56dc74f998 => Self::Phil, + _ => Self::Unknown, + } + } +} + diff --git a/inside/Cargo.lock b/inside/Cargo.lock index 206a49b..5c018c0 100644 --- a/inside/Cargo.lock +++ b/inside/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aead" diff --git a/outside/Cargo.lock b/outside/Cargo.lock index 070fb6e..2f072e2 100644 --- a/outside/Cargo.lock +++ b/outside/Cargo.lock @@ -265,6 +265,7 @@ name = "common" version = "0.1.0" dependencies = [ "serde", + "sha3", ] [[package]] @@ -1392,6 +1393,15 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + [[package]] name = "lalrpop" version = "0.19.12" @@ -2074,6 +2084,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f179d4e11094a893b82fff208f74d448a7512f99f5a0acbd5c679b705f83ed9" +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "siphasher" version = "0.3.11" diff --git a/outside/src/auth.rs b/outside/src/auth.rs index d9259ac..0693411 100644 --- a/outside/src/auth.rs +++ b/outside/src/auth.rs @@ -33,14 +33,15 @@ impl Authorized for Name { } } async fn from_badge(badge: u64) -> Self { - match badge { - badge => { + match Name::from_badge(badge) { + Name::Unknown => { if let Some(name) = NAMES.lock().await.borrow().get(badge) { *name } else { Name::Unknown } }, + badge => badge, } } } @@ -53,7 +54,7 @@ pub async fn send_badge(channel: Receiver<'static,CriticalSectionRawMutex,u64,1> let card = channel.receive().await; *LAST_BADGE.lock().await.borrow_mut() = card; - let name = Name::from_badge(card).await; + let name= ::from_badge(card).await; // this is also checked on the backend (TODO) if !name.authorized() { diff --git a/outside/src/music.rs b/outside/src/music.rs index 437dd02..5f6b194 100644 --- a/outside/src/music.rs +++ b/outside/src/music.rs @@ -47,7 +47,6 @@ impl Tracks for Name { Name::Thia => 7, Name::Michael => 0, Name::Zoey => 1, - Name::Coke => todo!(), Name::Unknown => 0, } } @@ -66,7 +65,6 @@ impl Tracks for Name { Name::Thia => "thia", Name::Michael => "michael", Name::Zoey => "zoey", - Name::Coke => "button", Name::Unknown => "", } } @@ -82,6 +80,7 @@ pub enum MusicCommand { /// 0-30 SetVolume(u8), Play(&'static str), + Button(), } #[embassy_executor::task] @@ -125,6 +124,10 @@ pub async fn music_manager(uart: UART1, irqs: Irqs, txp: PIN_20, rxp: PIN_21) -> } }, + MusicCommand::Button() => { + let index = rng.next_u32() % 12 as u32; + play_song("b", Some((index+1) as u8), &mut uart).await; + }, MusicCommand::Play(song) => { play_song(song, None, &mut uart).await }, diff --git a/server/Cargo.lock b/server/Cargo.lock index 06a9648..7012ba7 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -125,6 +125,15 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "byteorder" version = "1.5.0" @@ -154,6 +163,16 @@ name = "common" version = "0.1.0" dependencies = [ "serde", + "sha3", +] + +[[package]] +name = "cpufeatures" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" +dependencies = [ + "libc", ] [[package]] @@ -177,6 +196,16 @@ version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "deranged" version = "0.3.11" @@ -186,6 +215,16 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "embedded-io" version = "0.4.0" @@ -302,6 +341,16 @@ dependencies = [ "slab", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "gimli" version = "0.31.1" @@ -418,6 +467,15 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -748,6 +806,16 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1027,6 +1095,12 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.14" @@ -1039,6 +1113,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1"