diff options
Diffstat (limited to 'crates/chat-crypto/src/main.rs')
| -rw-r--r-- | crates/chat-crypto/src/main.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/crates/chat-crypto/src/main.rs b/crates/chat-crypto/src/main.rs index b6749cf..9ecfe22 100644 --- a/crates/chat-crypto/src/main.rs +++ b/crates/chat-crypto/src/main.rs @@ -13,11 +13,23 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -#![doc = "Command entry point for the isolated cryptographic compatibility probe."] +#![doc = "Isolated WASI command entry point for chat cryptography."] -use std::io::{self, Write}; +use std::io::{self, Read, Write}; fn main() -> io::Result<()> { - let result = stack_chat_crypto::compatibility_probe().map_err(io::Error::other)?; + let mut request = zeroize::Zeroizing::new(String::new()); + io::stdin() + .lock() + .take(8_388_609) + .read_to_string(&mut request)?; + let result = if request.is_empty() { + stack_chat_crypto::compatibility_probe().map_err(io::Error::other)? + } else { + match stack_chat_crypto::dispatch(&request) { + Ok(output) => output, + Err(error) => serde_json::to_string(&serde_json::json!({"error":error}))?, + } + }; writeln!(io::stdout().lock(), "{result}") } |
