hash stored badges

This commit is contained in:
Andy Killorin 2024-12-07 16:12:01 -05:00
commit 617fe896d7
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
3 changed files with 216 additions and 7 deletions

20
outside/Cargo.lock generated
View file

@ -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"

View file

@ -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= <Name as Authorized>::from_badge(card).await;
// this is also checked on the backend (TODO)
if !name.authorized() {

View file

@ -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
},