Mercurial > crates > nonstick
comparison src/pam_ffi/message.rs @ 74:c7c596e6388f
Make conversations type-safe (last big reorg) (REAL) (NOT CLICKBAIT)
In previous versions of Conversation, you could send messages and then
return messages of the wrong type or in the wrong order or whatever.
The receiver would then have to make sure that there were the right
number of messages and that each message was the right type.
That's annoying.
This change makes the `Message` enum a two-way channel, where the asker
puts their question into it, and then the answerer (the conversation)
puts the answer in and returns control to the asker. The asker then
only has to pull the Answer of the type they wanted out of the message.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Fri, 06 Jun 2025 22:21:17 -0400 |
parents | ac6881304c78 |
children |
comparison
equal
deleted
inserted
replaced
73:ac6881304c78 | 74:c7c596e6388f |
---|---|
124 let alloc = |style, text| Ok((style, memory::malloc_str(text)?.cast())); | 124 let alloc = |style, text| Ok((style, memory::malloc_str(text)?.cast())); |
125 match msg { | 125 match msg { |
126 Message::MaskedPrompt(text) => alloc(Style::PromptEchoOff, text), | 126 Message::MaskedPrompt(text) => alloc(Style::PromptEchoOff, text), |
127 Message::Prompt(text) => alloc(Style::PromptEchoOn, text), | 127 Message::Prompt(text) => alloc(Style::PromptEchoOn, text), |
128 Message::RadioPrompt(text) => alloc(Style::RadioType, text), | 128 Message::RadioPrompt(text) => alloc(Style::RadioType, text), |
129 Message::Error(text) => alloc(Style::ErrorMsg, text), | 129 Message::ErrorMsg(text) => alloc(Style::ErrorMsg, text), |
130 Message::Info(text) => alloc(Style::TextInfo, text), | 130 Message::InfoMsg(text) => alloc(Style::TextInfo, text), |
131 Message::BinaryPrompt { data, data_type } => Ok(( | 131 Message::BinaryPrompt { data, data_type } => Ok(( |
132 Style::BinaryPrompt, | 132 Style::BinaryPrompt, |
133 (CBinaryData::alloc(data, data_type)?).cast(), | 133 (CBinaryData::alloc(data, data_type)?).cast(), |
134 )), | 134 )), |
135 } | 135 } |
287 // SAFETY: We either allocated this message ourselves or were provided it by PAM. | 287 // SAFETY: We either allocated this message ourselves or were provided it by PAM. |
288 let result = unsafe { | 288 let result = unsafe { |
289 match style { | 289 match style { |
290 Style::PromptEchoOff => Message::MaskedPrompt(input.string_data()?), | 290 Style::PromptEchoOff => Message::MaskedPrompt(input.string_data()?), |
291 Style::PromptEchoOn => Message::Prompt(input.string_data()?), | 291 Style::PromptEchoOn => Message::Prompt(input.string_data()?), |
292 Style::TextInfo => Message::Info(input.string_data()?), | 292 Style::TextInfo => Message::InfoMsg(input.string_data()?), |
293 Style::ErrorMsg => Message::Error(input.string_data()?), | 293 Style::ErrorMsg => Message::ErrorMsg(input.string_data()?), |
294 Style::RadioType => Message::Error(input.string_data()?), | 294 Style::RadioType => Message::ErrorMsg(input.string_data()?), |
295 Style::BinaryPrompt => input.data.cast::<CBinaryData>().as_ref().map_or_else( | 295 Style::BinaryPrompt => input.data.cast::<CBinaryData>().as_ref().map_or_else( |
296 || Message::BinaryPrompt { | 296 || Message::BinaryPrompt { |
297 data_type: 0, | 297 data_type: 0, |
298 data: &[], | 298 data: &[], |
299 }, | 299 }, |