diff --git a/.ci/run-container-ci b/.ci/run-container-ci index 424518258..4450eedb5 100755 --- a/.ci/run-container-ci +++ b/.ci/run-container-ci @@ -25,7 +25,7 @@ set -e set -x -CONTAINER=shiftcrypto/firmware_v2:34 +CONTAINER=shiftcrypto/firmware_v2:35 if [ "$1" == "pull" ] ; then docker pull "$CONTAINER" diff --git a/Dockerfile b/Dockerfile index 17c2c96a4..241417ee3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -129,8 +129,8 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=/opt/ RUN rustup target add thumbv7em-none-eabi RUN rustup component add rustfmt RUN rustup component add clippy -RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.25.0 --locked -RUN CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.66.1 --locked +RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.26.0 --locked +RUN CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.69.0 --locked COPY tools/prost-build-proto prost-build-proto RUN CARGO_HOME=/opt/cargo cargo install --path prost-build-proto --locked diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock index cb177b2a1..973ffda7c 100644 --- a/src/rust/Cargo.lock +++ b/src/rust/Cargo.lock @@ -576,9 +576,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.5" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c01db6702aa05baa3f57dec92b8eeeeb4cb19e894e73996b32a4093289e54592" +checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" dependencies = [ "bytes", "prost-derive", @@ -586,15 +586,15 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.11.5" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8842bad1a5419bca14eac663ba798f6bc19c413c2fdceb5f3ba3b0932d96720" +checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" dependencies = [ "anyhow", "itertools", "proc-macro2", "quote", - "syn 1.0.105", + "syn 2.0.27", ] [[package]] diff --git a/src/rust/bitbox02-rust/Cargo.toml b/src/rust/bitbox02-rust/Cargo.toml index 7e0958d58..e6b624dbf 100644 --- a/src/rust/bitbox02-rust/Cargo.toml +++ b/src/rust/bitbox02-rust/Cargo.toml @@ -52,7 +52,7 @@ bitcoin = { version = "0.30.0", default-features = false, features = ["no-std"], [dependencies.prost] # keep version in sync with tools/prost-build/Cargo.toml. -version = "0.11.5" +version = "0.12.1" default-features = false features = ["prost-derive"] diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs index 7af05d64a..03e3bf7d2 100644 --- a/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs +++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs @@ -46,6 +46,7 @@ use pb::BtcCoin; use pb::BtcScriptConfig; use alloc::string::String; +use core::convert::TryFrom; use core::convert::TryInto; /// Like `hww::next_request`, but for Bitcoin requests/responses. @@ -193,8 +194,7 @@ pub async fn address_multisig( display: bool, ) -> Result { let coin_params = params::get(coin); - let script_type = - MultisigScriptType::from_i32(multisig.script_type).ok_or(Error::InvalidInput)?; + let script_type = MultisigScriptType::try_from(multisig.script_type)?; keypath::validate_address_multisig(keypath, coin_params.bip44_coin, script_type) .or(Err(Error::InvalidInput))?; let account_keypath = &keypath[..keypath.len() - 2]; @@ -266,27 +266,18 @@ async fn address_policy( /// Handle a Bitcoin xpub/address protobuf api call. pub async fn process_pub(request: &pb::BtcPubRequest) -> Result { - let coin = match BtcCoin::from_i32(request.coin) { - Some(coin) => coin, - None => return Err(Error::InvalidInput), - }; + let coin = BtcCoin::try_from(request.coin)?; coin_enabled(coin)?; match request.output { None => Err(Error::InvalidInput), Some(Output::XpubType(xpub_type)) => { - let xpub_type = match XPubType::from_i32(xpub_type) { - Some(xpub_type) => xpub_type, - None => return Err(Error::InvalidInput), - }; + let xpub_type = XPubType::try_from(xpub_type)?; xpub(coin, xpub_type, &request.keypath, request.display).await } Some(Output::ScriptConfig(BtcScriptConfig { config: Some(Config::SimpleType(simple_type)), })) => { - let simple_type = match SimpleType::from_i32(simple_type) { - Some(simple_type) => simple_type, - None => return Err(Error::InvalidInput), - }; + let simple_type = SimpleType::try_from(simple_type)?; address_simple(coin, simple_type, &request.keypath, request.display).await } Some(Output::ScriptConfig(BtcScriptConfig { diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/common.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/common.rs index 2af2487b9..4ee922a7d 100644 --- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/common.rs +++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/common.rs @@ -19,6 +19,7 @@ use crate::xpubcache::Bip32XpubCache; use alloc::string::String; use alloc::vec::Vec; +use core::convert::TryFrom; use bech32::{ToBase32, Variant}; @@ -126,8 +127,7 @@ impl Payload { // Note that the witness script has an additional varint prefix. let script_type = - pb::btc_script_config::multisig::ScriptType::from_i32(multisig.script_type) - .ok_or(Error::InvalidInput)?; + pb::btc_script_config::multisig::ScriptType::try_from(multisig.script_type)?; let script = multisig::pkscript(multisig, keypath_change, keypath_address)?; let payload_p2wsh = Payload { data: Sha256::digest(&script).to_vec(), @@ -182,8 +182,7 @@ impl Payload { }), .. } => { - let simple_type = pb::btc_script_config::SimpleType::from_i32(*simple_type) - .ok_or(Error::InvalidInput)?; + let simple_type = pb::btc_script_config::SimpleType::try_from(*simple_type)?; Self::from_simple(xpub_cache, params, simple_type, keypath) } pb::BtcScriptConfigWithKeypath { diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs index c89a5080d..c4770d147 100644 --- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs +++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs @@ -26,6 +26,7 @@ use crate::workflow::confirm; use alloc::string::String; use alloc::vec::Vec; +use core::convert::TryFrom; use core::convert::TryInto; use sha2::{Digest, Sha256}; @@ -61,7 +62,7 @@ pub fn get_hash( } { // 2. script config type - let byte: u8 = match ScriptType::from_i32(multisig.script_type).ok_or(())? { + let byte: u8 = match ScriptType::try_from(multisig.script_type).map_err(|_| ())? { ScriptType::P2wsh => 0x00, ScriptType::P2wshP2sh => 0x01, }; @@ -180,14 +181,14 @@ pub async fn confirm_extended( xpub_type: XPubType, keypath: &[u32], ) -> Result<(), Error> { - let script_type = ScriptType::from_i32(multisig.script_type).ok_or(Error::InvalidInput)?; + let script_type = ScriptType::try_from(multisig.script_type)?; confirm(title, params, name, multisig).await?; confirm::confirm(&confirm::Params { title, body: &format!( "{}\nat\n{}", - match ScriptType::from_i32(multisig.script_type).ok_or(Error::InvalidInput)? { + match ScriptType::try_from(multisig.script_type)? { ScriptType::P2wsh => "p2wsh", ScriptType::P2wshP2sh => "p2wsh-p2sh", }, @@ -265,7 +266,7 @@ pub fn validate(multisig: &Multisig, keypath: &[u32], expected_coin: u32) -> Res super::keypath::validate_account_multisig( keypath, expected_coin, - ScriptType::from_i32(multisig.script_type).ok_or(Error::InvalidInput)?, + ScriptType::try_from(multisig.script_type)?, ) .or(Err(Error::InvalidInput))?; diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/registration.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/registration.rs index 971bb2d1f..a641fa3e2 100644 --- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/registration.rs +++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/registration.rs @@ -23,6 +23,8 @@ use pb::btc_response::Response; use pb::btc_script_config::Config; use pb::BtcCoin; +use core::convert::TryFrom; + use super::multisig::SortXpubs; use crate::workflow::{confirm, status, trinary_input_string}; @@ -39,7 +41,7 @@ pub fn process_is_script_config_registered( }), keypath, }) => { - let coin = BtcCoin::from_i32(*coin).ok_or(Error::InvalidInput)?; + let coin = BtcCoin::try_from(*coin)?; Ok(Response::IsScriptConfigRegistered( pb::BtcIsScriptConfigRegisteredResponse { is_registered: super::multisig::get_name(coin, multisig, keypath)?.is_some(), @@ -54,7 +56,7 @@ pub fn process_is_script_config_registered( }), .. }) => { - let coin = BtcCoin::from_i32(*coin).ok_or(Error::InvalidInput)?; + let coin = BtcCoin::try_from(*coin)?; Ok(Response::IsScriptConfigRegistered( pb::BtcIsScriptConfigRegisteredResponse { is_registered: super::policies::get_name(coin, policy)?.is_some(), @@ -112,11 +114,11 @@ pub async fn process_register_script_config( }), keypath, }) => { - let coin = BtcCoin::from_i32(*coin).ok_or(Error::InvalidInput)?; + let coin = BtcCoin::try_from(*coin)?; let coin_params = params::get(coin); let name = get_name(request).await?; super::multisig::validate(multisig, keypath, coin_params.bip44_coin)?; - let xpub_type = XPubType::from_i32(request.xpub_type).ok_or(Error::InvalidInput)?; + let xpub_type = XPubType::try_from(request.xpub_type)?; super::multisig::confirm_extended( title, coin_params, @@ -146,7 +148,7 @@ pub async fn process_register_script_config( }), .. }) => { - let coin = BtcCoin::from_i32(*coin).ok_or(Error::InvalidInput)?; + let coin = BtcCoin::try_from(*coin)?; let coin_params = params::get(coin); let name = get_name(request).await?; super::policies::parse(policy)?.validate(coin)?; diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs index 35ce3730c..14f70b02b 100644 --- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs +++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs @@ -13,6 +13,7 @@ // limitations under the License. use alloc::vec::Vec; +use core::convert::TryFrom; use core::convert::TryInto; use sha2::{Digest, Sha256}; @@ -36,7 +37,7 @@ const MAX_MESSAGE_SIZE: usize = 1024; /// The result contains a 65 byte signature. The first 64 bytes are the secp256k1 signature in /// compact format (R and S values), and the last byte is the recoverable id (recid). pub async fn process(request: &pb::BtcSignMessageRequest) -> Result { - let coin = BtcCoin::from_i32(request.coin).ok_or(Error::InvalidInput)?; + let coin = BtcCoin::try_from(request.coin)?; if coin != BtcCoin::Btc { return Err(Error::InvalidInput); } @@ -47,10 +48,7 @@ pub async fn process(request: &pb::BtcSignMessageRequest) -> Result ( - keypath, - SimpleType::from_i32(*simple_type).ok_or(Error::InvalidInput)?, - ), + }) => (keypath, SimpleType::try_from(*simple_type)?), _ => return Err(Error::InvalidInput), }; if simple_type == SimpleType::P2tr { diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs index bb77e3406..65b75a053 100644 --- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs +++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs @@ -23,6 +23,7 @@ use crate::workflow::{confirm, status, transaction}; use crate::xpubcache::Bip32XpubCache; use alloc::vec::Vec; +use core::convert::TryFrom; use core::convert::TryInto; use pb::request::Request; @@ -194,8 +195,7 @@ fn validate_keypath( Some(pb::BtcScriptConfig { config: Some(pb::btc_script_config::Config::SimpleType(simple_type)), }) => { - let simple_type = pb::btc_script_config::SimpleType::from_i32(*simple_type) - .ok_or(Error::InvalidInput)?; + let simple_type = pb::btc_script_config::SimpleType::try_from(*simple_type)?; keypath::validate_address_simple( keypath, params.bip44_coin, @@ -208,8 +208,7 @@ fn validate_keypath( config: Some(pb::btc_script_config::Config::Multisig(multisig)), }) => { let script_type = - pb::btc_script_config::multisig::ScriptType::from_i32(multisig.script_type) - .ok_or(Error::InvalidInput)?; + pb::btc_script_config::multisig::ScriptType::try_from(multisig.script_type)?; keypath::validate_address_multisig(keypath, params.bip44_coin, script_type) .or(Err(Error::InvalidInput))?; } @@ -270,9 +269,7 @@ fn sighash_script( }), .. } => { - match pb::btc_script_config::SimpleType::from_i32(*simple_type) - .ok_or(Error::InvalidInput)? - { + match pb::btc_script_config::SimpleType::try_from(*simple_type)? { pb::btc_script_config::SimpleType::P2wpkhP2sh | pb::btc_script_config::SimpleType::P2wpkh => { // See https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#specification, item 5: @@ -453,8 +450,7 @@ async fn validate_script_configs( keypath::validate_account_simple( keypath, coin_params.bip44_coin, - pb::btc_script_config::SimpleType::from_i32(*simple_type) - .ok_or(Error::InvalidInput)?, + pb::btc_script_config::SimpleType::try_from(*simple_type)?, coin_params.taproot_support, ) .or(Err(Error::InvalidInput))?; @@ -556,10 +552,10 @@ async fn _process(request: &pb::BtcSignInitRequest) -> Result { return Err(Error::InvalidState); } // Validate the coin. - let coin = pb::BtcCoin::from_i32(request.coin).ok_or(Error::InvalidInput)?; + let coin = pb::BtcCoin::try_from(request.coin)?; let coin_params = super::params::get(coin); // Validate the format_unit. - let format_unit = FormatUnit::from_i32(request.format_unit).ok_or(Error::InvalidInput)?; + let format_unit = FormatUnit::try_from(request.format_unit)?; // Currently we do not support time-based nlocktime if request.locktime >= 500000000 { return Err(Error::InvalidInput); @@ -752,8 +748,7 @@ async fn _process(request: &pb::BtcSignInitRequest) -> Result { // Take payload from provided output. common::Payload { data: tx_output.payload.clone(), - output_type: pb::BtcOutputType::from_i32(tx_output.r#type) - .ok_or(Error::InvalidInput)?, + output_type: pb::BtcOutputType::try_from(tx_output.r#type)?, } }; @@ -1330,7 +1325,7 @@ mod tests { /// Return the transaction part requested by the device. fn make_host_request(&self, response: Response) -> Request { let next = extract_next(&response); - match NextType::from_i32(next.r#type).unwrap() { + match NextType::try_from(next.r#type).unwrap() { NextType::Input => { Request::BtcSignInput(self.inputs[next.index as usize].input.clone()) } @@ -1607,7 +1602,7 @@ mod tests { *crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = Some(Box::new(move |response: Response| { let next = extract_next(&response); - if NextType::from_i32(next.r#type).unwrap() == NextType::PrevtxInit { + if NextType::try_from(next.r#type).unwrap() == NextType::PrevtxInit { unsafe { PREVTX_REQUESTED += 1 } } Ok(tx.borrow().make_host_request(response)) @@ -1853,7 +1848,7 @@ mod tests { *crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = Some(Box::new(move |response: Response| { let next = extract_next(&response); - if NextType::from_i32(next.r#type).unwrap() == NextType::PrevtxInit { + if NextType::try_from(next.r#type).unwrap() == NextType::PrevtxInit { unsafe { PREVTX_REQUESTED = true } } Ok(tx.borrow().make_host_request(response)) @@ -1897,7 +1892,7 @@ mod tests { *crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = Some(Box::new(move |response: Response| { let next = extract_next(&response); - if NextType::from_i32(next.r#type).unwrap() == NextType::PrevtxInit { + if NextType::try_from(next.r#type).unwrap() == NextType::PrevtxInit { unsafe { PREVTX_REQUESTED += 1 } } Ok(tx.borrow().make_host_request(response)) @@ -2360,7 +2355,7 @@ mod tests { Some(Box::new(move |response: Response| { let tx = tx.borrow(); let next = extract_next(&response); - match NextType::from_i32(next.r#type).unwrap() { + match NextType::try_from(next.r#type).unwrap() { NextType::Output => unsafe { PASS2 = true }, NextType::Input => { if unsafe { PASS2 } { @@ -2406,7 +2401,7 @@ mod tests { Some(Box::new(move |response: Response| { let tx = tx.borrow(); let next = extract_next(&response); - match NextType::from_i32(next.r#type).unwrap() { + match NextType::try_from(next.r#type).unwrap() { NextType::Output => unsafe { PASS2 = true }, NextType::Input => { if unsafe { PASS2 } { @@ -2446,7 +2441,7 @@ mod tests { Some(Box::new(move |response: Response| { let tx = tx.borrow(); let next = extract_next(&response); - match NextType::from_i32(next.r#type).unwrap() { + match NextType::try_from(next.r#type).unwrap() { NextType::Output => { let mut output = tx.outputs[next.index as usize].clone(); if next.index == 0 { @@ -2475,7 +2470,7 @@ mod tests { Some(Box::new(move |response: Response| { let tx = tx.borrow(); let next = extract_next(&response); - match NextType::from_i32(next.r#type).unwrap() { + match NextType::try_from(next.r#type).unwrap() { NextType::Output => { let mut output = tx.outputs[next.index as usize].clone(); if next.index == 4 { diff --git a/src/rust/bitbox02-rust/src/hww/api/cardano/address.rs b/src/rust/bitbox02-rust/src/hww/api/cardano/address.rs index b2ac92467..4ebc2840f 100644 --- a/src/rust/bitbox02-rust/src/hww/api/cardano/address.rs +++ b/src/rust/bitbox02-rust/src/hww/api/cardano/address.rs @@ -17,6 +17,7 @@ use super::Error; use alloc::string::String; use alloc::vec::Vec; +use core::convert::TryFrom; use crate::workflow::confirm; @@ -199,7 +200,7 @@ pub fn validate_and_encode_payment_address( } pub async fn process(request: &pb::CardanoAddressRequest) -> Result { - let network = CardanoNetwork::from_i32(request.network).ok_or(Error::InvalidInput)?; + let network = CardanoNetwork::try_from(request.network)?; let params = params::get(network); let script_config: &Config = request .script_config diff --git a/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs b/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs index d7fe81cb9..cb683b8a3 100644 --- a/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs +++ b/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs @@ -20,6 +20,7 @@ use super::Error; use alloc::string::String; use alloc::vec::Vec; +use core::convert::TryFrom; use bech32::{ToBase32, Variant}; use blake2::{ @@ -122,7 +123,7 @@ fn validate_asset_groups( } async fn _process(request: &pb::CardanoSignTransactionRequest) -> Result { - let network = CardanoNetwork::from_i32(request.network).ok_or(Error::InvalidInput)?; + let network = CardanoNetwork::try_from(request.network)?; let params = params::get(network); if request.inputs.is_empty() { return Err(Error::InvalidInput); diff --git a/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction/cbor.rs b/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction/cbor.rs index dd172e0c1..65e7cace0 100644 --- a/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction/cbor.rs +++ b/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction/cbor.rs @@ -17,6 +17,7 @@ use super::super::pb; use super::super::Error; use alloc::vec::Vec; +use core::convert::TryFrom; use digest::Update; use minicbor::encode::{Encoder, Write}; @@ -80,7 +81,7 @@ pub fn encode_transaction_body( tx: &pb::CardanoSignTransactionRequest, writer: W, ) -> Result<(), Error> { - let params = params::get(pb::CardanoNetwork::from_i32(tx.network).ok_or(Error::InvalidInput)?); + let params = params::get(pb::CardanoNetwork::try_from(tx.network)?); let mut encoder = Encoder::new(writer); let mut num_map_entries = 3; // inputs, outputs, fee diff --git a/src/rust/bitbox02-rust/src/hww/api/error.rs b/src/rust/bitbox02-rust/src/hww/api/error.rs index 349cbb4df..e8889ef55 100644 --- a/src/rust/bitbox02-rust/src/hww/api/error.rs +++ b/src/rust/bitbox02-rust/src/hww/api/error.rs @@ -107,6 +107,12 @@ impl core::convert::From for Error { } } +impl core::convert::From for Error { + fn from(_error: prost::DecodeError) -> Self { + Error::InvalidInput + } +} + use pb::response::Response; /// Creates an Error response. Corresponds to commander.c:_report_error(). diff --git a/src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs b/src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs index f389e8d8a..a203dc419 100644 --- a/src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs +++ b/src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs @@ -22,10 +22,11 @@ use crate::bip32; use crate::keystore; use crate::workflow::confirm; +use core::convert::TryFrom; use core::convert::TryInto; async fn process_address(request: &pb::EthPubRequest) -> Result { - let coin = pb::EthCoin::from_i32(request.coin).ok_or(Error::InvalidInput)?; + let coin = pb::EthCoin::try_from(request.coin)?; let params = super::params::get_and_warn_unknown(coin, request.chain_id).await?; // If a contract_address is provided, it has to be a supported ERC20-token. @@ -88,7 +89,7 @@ fn process_xpub(request: &pb::EthPubRequest) -> Result { } pub async fn process(request: &pb::EthPubRequest) -> Result { - let output_type = OutputType::from_i32(request.output_type).ok_or(Error::InvalidInput)?; + let output_type = OutputType::try_from(request.output_type)?; match output_type { OutputType::Address => process_address(request).await, OutputType::Xpub => process_xpub(request), diff --git a/src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs b/src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs index e6b55e76f..2e8d38d12 100644 --- a/src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs +++ b/src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs @@ -22,6 +22,7 @@ use bitbox02::keystore; use crate::workflow::{confirm, status, transaction}; use alloc::vec::Vec; +use core::convert::TryFrom; use core::convert::TryInto; use pb::eth_response::Response; @@ -178,7 +179,7 @@ async fn verify_standard_transaction( /// Verify and sign an Ethereum transaction. pub async fn process(request: &pb::EthSignRequest) -> Result { - let coin = pb::EthCoin::from_i32(request.coin).ok_or(Error::InvalidInput)?; + let coin = pb::EthCoin::try_from(request.coin)?; let params = super::params::get_and_warn_unknown(coin, request.chain_id).await?; if !super::keypath::is_valid_keypath_address(&request.keypath) { diff --git a/src/rust/bitbox02-rust/src/hww/api/ethereum/sign_typed_msg.rs b/src/rust/bitbox02-rust/src/hww/api/ethereum/sign_typed_msg.rs index 65d1a8617..31e2c8784 100644 --- a/src/rust/bitbox02-rust/src/hww/api/ethereum/sign_typed_msg.rs +++ b/src/rust/bitbox02-rust/src/hww/api/ethereum/sign_typed_msg.rs @@ -32,6 +32,7 @@ use alloc::boxed::Box; use alloc::string::{String, ToString}; use alloc::vec::Vec; +use core::convert::TryFrom; use core::convert::TryInto; use sha3::digest::Digest; @@ -75,7 +76,7 @@ fn get_transitive_types<'a>(types: &'a [StructType], name: &'a str) -> Result Result { - let formatted = match DataType::from_i32(typ.r#type).ok_or(Error::InvalidInput)? { + let formatted = match DataType::try_from(typ.r#type)? { DataType::Unknown => return Err(Error::InvalidInput), DataType::Bytes => { if typ.size == 0 { @@ -198,7 +199,7 @@ async fn get_value_from_host(root_object: RootObject, path: &[u32]) -> Result) -> Result<(Vec, String), Error> { - let result = match DataType::from_i32(typ.r#type).ok_or(Error::InvalidInput)? { + let result = match DataType::try_from(typ.r#type)? { DataType::Unknown => return Err(Error::InvalidInput), DataType::Bytes => { let encoded = if typ.size > 0 { @@ -683,7 +684,7 @@ mod tests { root_object, path, })), - }) => match RootObject::from_i32(*root_object).unwrap() { + }) => match RootObject::try_from(*root_object).unwrap() { RootObject::Domain => return Some(self.domain.get_value_protobuf(path)), RootObject::Message => return Some(self.message.get_value_protobuf(path)), _ => {} diff --git a/src/rust/bitbox02-rust/src/hww/api/sdcard.rs b/src/rust/bitbox02-rust/src/hww/api/sdcard.rs index c29b6b198..ea047d5bb 100644 --- a/src/rust/bitbox02-rust/src/hww/api/sdcard.rs +++ b/src/rust/bitbox02-rust/src/hww/api/sdcard.rs @@ -20,13 +20,15 @@ use pb::response::Response; use crate::workflow::sdcard; +use core::convert::TryFrom; + pub async fn process( &pb::InsertRemoveSdCardRequest { action }: &pb::InsertRemoveSdCardRequest, ) -> Result { let inserted = bitbox02::sd::sdcard_inserted(); - let action = match SdCardAction::from_i32(action) { - Some(action) => action, - None => return Ok(Response::Success(pb::Success {})), + let action = match SdCardAction::try_from(action) { + Ok(action) => action, + Err(_) => return Ok(Response::Success(pb::Success {})), }; // No action required, already inserted (INSERT request) or not inserted (REMOVE request) if (action == SdCardAction::InsertCard && inserted) diff --git a/src/rust/bitbox02-rust/src/hww/api/system.rs b/src/rust/bitbox02-rust/src/hww/api/system.rs index b2fe61ec8..ee7061a6f 100644 --- a/src/rust/bitbox02-rust/src/hww/api/system.rs +++ b/src/rust/bitbox02-rust/src/hww/api/system.rs @@ -14,6 +14,7 @@ use super::Error; use crate::pb; +use core::convert::TryFrom; use pb::reboot_request::Purpose; use pb::response::Response; @@ -23,12 +24,12 @@ use crate::workflow::confirm; pub async fn reboot(&pb::RebootRequest { purpose }: &pb::RebootRequest) -> Result { confirm::confirm(&confirm::Params { title: "", - body: match Purpose::from_i32(purpose) { - Some(Purpose::Upgrade) => "Proceed to upgrade?", - Some(Purpose::Settings) => "Go to\nstartup settings?", + body: match Purpose::try_from(purpose) { + Ok(Purpose::Upgrade) => "Proceed to upgrade?", + Ok(Purpose::Settings) => "Go to\nstartup settings?", // No error, if new client library sends a purpose that we don't understand, // we reboot anyway. - None => "Reboot?", + Err(_) => "Reboot?", }, ..Default::default() }) diff --git a/src/rust/rust-toolchain b/src/rust/rust-toolchain index 0834888f5..5e3a42566 100644 --- a/src/rust/rust-toolchain +++ b/src/rust/rust-toolchain @@ -1 +1 @@ -1.72.0 +1.73.0 diff --git a/src/rust/vendor/prost-derive/.cargo-checksum.json b/src/rust/vendor/prost-derive/.cargo-checksum.json index 062a64249..3fc2ef84e 100644 --- a/src/rust/vendor/prost-derive/.cargo-checksum.json +++ b/src/rust/vendor/prost-derive/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"830ca416b545d756142214029e79dd0def97b991527623943fce4275667628d4","LICENSE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","README.md":"6c67fa1e48f14adfaf834f520f798ddfb79f90804f46cc215ee391a7d57913a4","src/field/group.rs":"0370fda09a6dc7e8e91cfab1a6638c0117f0b968bcc7d1a8f397c2bf00042481","src/field/map.rs":"30b678fbbeca1411e7e16f2dfeadf38860ba654266ad66da16019369153618f2","src/field/message.rs":"a5672412435bb9fafbd4a99b1a6c6d5bbf636a571959358a44196bfd69efc2d1","src/field/mod.rs":"5265820ea953a100ee33db71c416f72bac5e1dd375a98ebdd6755a334f5bed0f","src/field/oneof.rs":"4fc488445b05e464070fadd8799cafb806db5c23d1494c4300cb293394863012","src/field/scalar.rs":"6859f9910a12a2864397f7f6fa36541c992c43b3ff8d15d4191aa93e92f5b078","src/lib.rs":"8ba979a94503dcd8d487237e856367a0a345b4873de7a73135c1b577ecb16bd9"},"package":"c8842bad1a5419bca14eac663ba798f6bc19c413c2fdceb5f3ba3b0932d96720"} \ No newline at end of file +{"files":{"Cargo.toml":"7d555d8783ebeebdb3c3190ff57fa833db7cbd14eecba8a5a101f87e7dca3f71","LICENSE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","README.md":"6c67fa1e48f14adfaf834f520f798ddfb79f90804f46cc215ee391a7d57913a4","src/field/group.rs":"0370fda09a6dc7e8e91cfab1a6638c0117f0b968bcc7d1a8f397c2bf00042481","src/field/map.rs":"a03791fc758802cdf4e75e197acd7975141377e3d1ad1273e6cefab2b7fddfe9","src/field/message.rs":"a5672412435bb9fafbd4a99b1a6c6d5bbf636a571959358a44196bfd69efc2d1","src/field/mod.rs":"108b98c676b780fbe55907a3c2825bdf77cd0f857292bfa82a78f5b20fa499c5","src/field/oneof.rs":"128e990b8bb711fdbadd35b711f127c02f64b84b5ca95307b428956896d15721","src/field/scalar.rs":"16a4210578e7e643d49b5c769078f8bf295dae738f3ba2b6e48af7291b9e7951","src/lib.rs":"0b86c9fdace3d3f942afad55f7aa21d4dc2c7d8447906d03fd9c650d311c47ee"},"package":"265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32"} \ No newline at end of file diff --git a/src/rust/vendor/prost-derive/Cargo.toml b/src/rust/vendor/prost-derive/Cargo.toml index 1cf08498e..768b03f28 100644 --- a/src/rust/vendor/prost-derive/Cargo.toml +++ b/src/rust/vendor/prost-derive/Cargo.toml @@ -11,9 +11,9 @@ [package] edition = "2021" -rust-version = "1.56" +rust-version = "1.60" name = "prost-derive" -version = "0.11.5" +version = "0.12.1" authors = [ "Dan Burkert ", "Lucio Franco ", @@ -32,7 +32,7 @@ proc_macro = true version = "1.0.1" [dependencies.itertools] -version = "0.10" +version = ">=0.10, <0.12" features = ["use_alloc"] default-features = false @@ -43,5 +43,5 @@ version = "1" version = "1" [dependencies.syn] -version = "1.0.3" +version = "2" features = ["extra-traits"] diff --git a/src/rust/vendor/prost-derive/src/field/map.rs b/src/rust/vendor/prost-derive/src/field/map.rs index 6c70fb364..4855cc5c6 100644 --- a/src/rust/vendor/prost-derive/src/field/map.rs +++ b/src/rust/vendor/prost-derive/src/field/map.rs @@ -1,7 +1,8 @@ use anyhow::{bail, Error}; use proc_macro2::{Span, TokenStream}; use quote::quote; -use syn::{Ident, Lit, Meta, MetaNameValue, NestedMeta}; +use syn::punctuated::Punctuated; +use syn::{Expr, ExprLit, Ident, Lit, Meta, MetaNameValue, Token}; use crate::field::{scalar, set_option, tag_attr}; @@ -67,7 +68,11 @@ impl Field { { let (k, v): (String, String) = match attr { Meta::NameValue(MetaNameValue { - lit: Lit::Str(lit), .. + value: + Expr::Lit(ExprLit { + lit: Lit::Str(lit), .. + }), + .. }) => { let items = lit.value(); let mut items = items.split(',').map(ToString::to_string); @@ -82,23 +87,14 @@ impl Field { (k, v) } Meta::List(meta_list) => { - // TODO(rustlang/rust#23121): slice pattern matching would make this much nicer. - if meta_list.nested.len() != 2 { + let nested = meta_list + .parse_args_with(Punctuated::::parse_terminated)? + .into_iter() + .collect::>(); + if nested.len() != 2 { bail!("invalid map attribute: must contain key and value types"); } - let k = match &meta_list.nested[0] { - NestedMeta::Meta(Meta::Path(k)) if k.get_ident().is_some() => { - k.get_ident().unwrap().to_string() - } - _ => bail!("invalid map attribute: key must be an identifier"), - }; - let v = match &meta_list.nested[1] { - NestedMeta::Meta(Meta::Path(v)) if v.get_ident().is_some() => { - v.get_ident().unwrap().to_string() - } - _ => bail!("invalid map attribute: value must be an identifier"), - }; - (k, v) + (nested[0].to_string(), nested[1].to_string()) } _ => return Ok(None), }; @@ -279,11 +275,17 @@ impl Field { Some(quote! { #[doc=#get_doc] pub fn #get(&self, key: #key_ref_ty) -> ::core::option::Option<#ty> { - self.#ident.get(#take_ref key).cloned().and_then(#ty::from_i32) + self.#ident.get(#take_ref key).cloned().and_then(|x| { + let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x); + result.ok() + }) } #[doc=#insert_doc] pub fn #insert(&mut self, key: #key_ty, value: #ty) -> ::core::option::Option<#ty> { - self.#ident.insert(key, value as i32).and_then(#ty::from_i32) + self.#ident.insert(key, value as i32).and_then(|x| { + let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x); + result.ok() + }) } }) } else { diff --git a/src/rust/vendor/prost-derive/src/field/mod.rs b/src/rust/vendor/prost-derive/src/field/mod.rs index fcd8adaa0..4bec5617c 100644 --- a/src/rust/vendor/prost-derive/src/field/mod.rs +++ b/src/rust/vendor/prost-derive/src/field/mod.rs @@ -10,7 +10,8 @@ use std::slice; use anyhow::{bail, Error}; use proc_macro2::TokenStream; use quote::quote; -use syn::{Attribute, Lit, LitBool, Meta, MetaList, MetaNameValue, NestedMeta}; +use syn::punctuated::Punctuated; +use syn::{Attribute, Expr, ExprLit, Lit, LitBool, LitInt, Meta, MetaNameValue, Token}; #[derive(Clone)] pub enum Field { @@ -32,7 +33,7 @@ impl Field { /// If the meta items are invalid, an error will be returned. /// If the field should be ignored, `None` is returned. pub fn new(attrs: Vec, inferred_tag: Option) -> Result, Error> { - let attrs = prost_attrs(attrs); + let attrs = prost_attrs(attrs)?; // TODO: check for ignore attribute. @@ -58,7 +59,7 @@ impl Field { /// If the meta items are invalid, an error will be returned. /// If the field should be ignored, `None` is returned. pub fn new_oneof(attrs: Vec) -> Result, Error> { - let attrs = prost_attrs(attrs); + let attrs = prost_attrs(attrs)?; // TODO: check for ignore attribute. @@ -224,27 +225,20 @@ impl fmt::Display for Label { } /// Get the items belonging to the 'prost' list attribute, e.g. `#[prost(foo, bar="baz")]`. -fn prost_attrs(attrs: Vec) -> Vec { - attrs - .iter() - .flat_map(Attribute::parse_meta) - .flat_map(|meta| match meta { - Meta::List(MetaList { path, nested, .. }) => { - if path.is_ident("prost") { - nested.into_iter().collect() - } else { - Vec::new() - } - } - _ => Vec::new(), - }) - .flat_map(|attr| -> Result<_, _> { - match attr { - NestedMeta::Meta(attr) => Ok(attr), - NestedMeta::Lit(lit) => bail!("invalid prost attribute: {:?}", lit), +fn prost_attrs(attrs: Vec) -> Result, Error> { + let mut result = Vec::new(); + for attr in attrs.iter() { + if let Meta::List(meta_list) = &attr.meta { + if meta_list.path.is_ident("prost") { + result.extend( + meta_list + .parse_args_with(Punctuated::::parse_terminated)? + .into_iter(), + ) } - }) - .collect() + } + } + Ok(result) } pub fn set_option(option: &mut Option, value: T, message: &str) -> Result<(), Error> @@ -276,16 +270,14 @@ fn bool_attr(key: &str, attr: &Meta) -> Result, Error> { match *attr { Meta::Path(..) => Ok(Some(true)), Meta::List(ref meta_list) => { - // TODO(rustlang/rust#23121): slice pattern matching would make this much nicer. - if meta_list.nested.len() == 1 { - if let NestedMeta::Lit(Lit::Bool(LitBool { value, .. })) = meta_list.nested[0] { - return Ok(Some(value)); - } - } - bail!("invalid {} attribute", key); + return Ok(Some(meta_list.parse_args::()?.value())); } Meta::NameValue(MetaNameValue { - lit: Lit::Str(ref lit), + value: + Expr::Lit(ExprLit { + lit: Lit::Str(ref lit), + .. + }), .. }) => lit .value() @@ -293,7 +285,11 @@ fn bool_attr(key: &str, attr: &Meta) -> Result, Error> { .map_err(Error::from) .map(Option::Some), Meta::NameValue(MetaNameValue { - lit: Lit::Bool(LitBool { value, .. }), + value: + Expr::Lit(ExprLit { + lit: Lit::Bool(LitBool { value, .. }), + .. + }), .. }) => Ok(Some(value)), _ => bail!("invalid {} attribute", key), @@ -315,15 +311,12 @@ pub(super) fn tag_attr(attr: &Meta) -> Result, Error> { } match *attr { Meta::List(ref meta_list) => { - // TODO(rustlang/rust#23121): slice pattern matching would make this much nicer. - if meta_list.nested.len() == 1 { - if let NestedMeta::Lit(Lit::Int(ref lit)) = meta_list.nested[0] { - return Ok(Some(lit.base10_parse()?)); - } - } - bail!("invalid tag attribute: {:?}", attr); + return Ok(Some(meta_list.parse_args::()?.base10_parse()?)); } - Meta::NameValue(ref meta_name_value) => match meta_name_value.lit { + Meta::NameValue(MetaNameValue { + value: Expr::Lit(ref expr), + .. + }) => match expr.lit { Lit::Str(ref lit) => lit .value() .parse::() @@ -341,19 +334,19 @@ fn tags_attr(attr: &Meta) -> Result>, Error> { return Ok(None); } match *attr { - Meta::List(ref meta_list) => { - let mut tags = Vec::with_capacity(meta_list.nested.len()); - for item in &meta_list.nested { - if let NestedMeta::Lit(Lit::Int(ref lit)) = *item { - tags.push(lit.base10_parse()?); - } else { - bail!("invalid tag attribute: {:?}", attr); - } - } - Ok(Some(tags)) - } + Meta::List(ref meta_list) => Ok(Some( + meta_list + .parse_args_with(Punctuated::::parse_terminated)? + .iter() + .map(LitInt::base10_parse) + .collect::, _>>()?, + )), Meta::NameValue(MetaNameValue { - lit: Lit::Str(ref lit), + value: + Expr::Lit(ExprLit { + lit: Lit::Str(ref lit), + .. + }), .. }) => lit .value() diff --git a/src/rust/vendor/prost-derive/src/field/oneof.rs b/src/rust/vendor/prost-derive/src/field/oneof.rs index 7e7f08671..78c77eeb1 100644 --- a/src/rust/vendor/prost-derive/src/field/oneof.rs +++ b/src/rust/vendor/prost-derive/src/field/oneof.rs @@ -1,7 +1,7 @@ use anyhow::{bail, Error}; use proc_macro2::TokenStream; use quote::quote; -use syn::{parse_str, Lit, Meta, MetaNameValue, NestedMeta, Path}; +use syn::{parse_str, Expr, ExprLit, Ident, Lit, Meta, MetaNameValue, Path}; use crate::field::{set_option, tags_attr}; @@ -21,21 +21,14 @@ impl Field { if attr.path().is_ident("oneof") { let t = match *attr { Meta::NameValue(MetaNameValue { - lit: Lit::Str(ref lit), + value: + Expr::Lit(ExprLit { + lit: Lit::Str(ref lit), + .. + }), .. }) => parse_str::(&lit.value())?, - Meta::List(ref list) if list.nested.len() == 1 => { - // TODO(rustlang/rust#23121): slice pattern matching would make this much nicer. - if let NestedMeta::Meta(Meta::Path(ref path)) = list.nested[0] { - if let Some(ident) = path.get_ident() { - Path::from(ident.clone()) - } else { - bail!("invalid oneof attribute: item must be an identifier"); - } - } else { - bail!("invalid oneof attribute: item must be an identifier"); - } - } + Meta::List(ref list) => list.parse_args::()?.into(), _ => bail!("invalid oneof attribute: {:?}", attr), }; set_option(&mut ty, t, "duplicate oneof attribute")?; diff --git a/src/rust/vendor/prost-derive/src/field/scalar.rs b/src/rust/vendor/prost-derive/src/field/scalar.rs index 6a2fb96d6..5a3dfb2ec 100644 --- a/src/rust/vendor/prost-derive/src/field/scalar.rs +++ b/src/rust/vendor/prost-derive/src/field/scalar.rs @@ -4,9 +4,7 @@ use std::fmt; use anyhow::{anyhow, bail, Error}; use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens, TokenStreamExt}; -use syn::{ - parse_str, Ident, Index, Lit, LitByteStr, Meta, MetaList, MetaNameValue, NestedMeta, Path, -}; +use syn::{parse_str, Expr, ExprLit, Ident, Index, Lit, LitByteStr, Meta, MetaNameValue, Path}; use crate::field::{bool_attr, set_option, tag_attr, Label}; @@ -221,15 +219,17 @@ impl Field { struct #wrap_name<'a>(&'a i32); impl<'a> ::core::fmt::Debug for #wrap_name<'a> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - match #ty::from_i32(*self.0) { - None => ::core::fmt::Debug::fmt(&self.0, f), - Some(en) => ::core::fmt::Debug::fmt(&en, f), + let res: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(*self.0); + match res { + Err(_) => ::core::fmt::Debug::fmt(&self.0, f), + Ok(en) => ::core::fmt::Debug::fmt(&en, f), } } } } } else { quote! { + #[allow(non_snake_case)] fn #wrap_name(v: T) -> T { v } } } @@ -297,7 +297,7 @@ impl Field { quote! { #[doc=#get_doc] pub fn #get(&self) -> #ty { - #ty::from_i32(self.#ident).unwrap_or(#default) + ::core::convert::TryFrom::try_from(self.#ident).unwrap_or(#default) } #[doc=#set_doc] @@ -315,7 +315,10 @@ impl Field { quote! { #[doc=#get_doc] pub fn #get(&self) -> #ty { - self.#ident.and_then(#ty::from_i32).unwrap_or(#default) + self.#ident.and_then(|x| { + let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x); + result.ok() + }).unwrap_or(#default) } #[doc=#set_doc] @@ -337,7 +340,10 @@ impl Field { ::core::iter::Cloned<::core::slice::Iter>, fn(i32) -> ::core::option::Option<#ty>, > { - self.#ident.iter().cloned().filter_map(#ty::from_i32) + self.#ident.iter().cloned().filter_map(|x| { + let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x); + result.ok() + }) } #[doc=#push_doc] pub fn #push(&mut self, value: #ty) { @@ -439,29 +445,24 @@ impl Ty { Meta::Path(ref name) if name.is_ident("bytes") => Ty::Bytes(BytesTy::Vec), Meta::NameValue(MetaNameValue { ref path, - lit: Lit::Str(ref l), + value: + Expr::Lit(ExprLit { + lit: Lit::Str(ref l), + .. + }), .. }) if path.is_ident("bytes") => Ty::Bytes(BytesTy::try_from_str(&l.value())?), Meta::NameValue(MetaNameValue { ref path, - lit: Lit::Str(ref l), + value: + Expr::Lit(ExprLit { + lit: Lit::Str(ref l), + .. + }), .. }) if path.is_ident("enumeration") => Ty::Enumeration(parse_str::(&l.value())?), - Meta::List(MetaList { - ref path, - ref nested, - .. - }) if path.is_ident("enumeration") => { - // TODO(rustlang/rust#23121): slice pattern matching would make this much nicer. - if nested.len() == 1 { - if let NestedMeta::Meta(Meta::Path(ref path)) = nested[0] { - Ty::Enumeration(path.clone()) - } else { - bail!("invalid enumeration attribute: item must be an identifier"); - } - } else { - bail!("invalid enumeration attribute: only a single identifier is supported"); - } + Meta::List(ref meta_list) if meta_list.path.is_ident("enumeration") => { + Ty::Enumeration(meta_list.parse_args::()?) } _ => return Ok(None), }; @@ -618,8 +619,12 @@ impl DefaultValue { pub fn from_attr(attr: &Meta) -> Result, Error> { if !attr.path().is_ident("default") { Ok(None) - } else if let Meta::NameValue(ref name_value) = *attr { - Ok(Some(name_value.lit.clone())) + } else if let Meta::NameValue(MetaNameValue { + value: Expr::Lit(ExprLit { ref lit, .. }), + .. + }) = *attr + { + Ok(Some(lit.clone())) } else { bail!("invalid default value attribute: {:?}", attr) } diff --git a/src/rust/vendor/prost-derive/src/lib.rs b/src/rust/vendor/prost-derive/src/lib.rs index 1713c34d6..8bc99c5ed 100644 --- a/src/rust/vendor/prost-derive/src/lib.rs +++ b/src/rust/vendor/prost-derive/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/prost-derive/0.11.5")] +#![doc(html_root_url = "https://docs.rs/prost-derive/0.12.1")] // The `quote!` macro requires deep recursion. #![recursion_limit = "4096"] @@ -23,6 +23,12 @@ fn try_message(input: TokenStream) -> Result { let ident = input.ident; + syn::custom_keyword!(skip_debug); + let skip_debug = input + .attrs + .into_iter() + .any(|a| a.path().is_ident("prost") && a.parse_args::().is_ok()); + let variant_data = match input.data { Data::Struct(variant_data) => variant_data, Data::Enum(..) => bail!("Message can not be derived for an enum"), @@ -165,26 +171,6 @@ fn try_message(input: TokenStream) -> Result { } }; - let debugs = unsorted_fields.iter().map(|&(ref field_ident, ref field)| { - let wrapper = field.debug(quote!(self.#field_ident)); - let call = if is_struct { - quote!(builder.field(stringify!(#field_ident), &wrapper)) - } else { - quote!(builder.field(&wrapper)) - }; - quote! { - let builder = { - let wrapper = #wrapper; - #call - }; - } - }); - let debug_builder = if is_struct { - quote!(f.debug_struct(stringify!(#ident))) - } else { - quote!(f.debug_tuple(stringify!(#ident))) - }; - let expanded = quote! { impl #impl_generics ::prost::Message for #ident #ty_generics #where_clause { #[allow(unused_variables)] @@ -223,14 +209,44 @@ fn try_message(input: TokenStream) -> Result { #default } } + }; + let expanded = if skip_debug { + expanded + } else { + let debugs = unsorted_fields.iter().map(|&(ref field_ident, ref field)| { + let wrapper = field.debug(quote!(self.#field_ident)); + let call = if is_struct { + quote!(builder.field(stringify!(#field_ident), &wrapper)) + } else { + quote!(builder.field(&wrapper)) + }; + quote! { + let builder = { + let wrapper = #wrapper; + #call + }; + } + }); + let debug_builder = if is_struct { + quote!(f.debug_struct(stringify!(#ident))) + } else { + quote!(f.debug_tuple(stringify!(#ident))) + }; + quote! { + #expanded - impl #impl_generics ::core::fmt::Debug for #ident #ty_generics #where_clause { - fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - let mut builder = #debug_builder; - #(#debugs;)* - builder.finish() + impl #impl_generics ::core::fmt::Debug for #ident #ty_generics #where_clause { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + let mut builder = #debug_builder; + #(#debugs;)* + builder.finish() + } } } + }; + + let expanded = quote! { + #expanded #methods }; @@ -274,7 +290,7 @@ fn try_enumeration(input: TokenStream) -> Result { match discriminant { Some((_, expr)) => variants.push((ident, expr)), - None => bail!("Enumeration variants must have a disriminant"), + None => bail!("Enumeration variants must have a discriminant"), } } @@ -291,6 +307,10 @@ fn try_enumeration(input: TokenStream) -> Result { |&(ref variant, ref value)| quote!(#value => ::core::option::Option::Some(#ident::#variant)), ); + let try_from = variants.iter().map( + |&(ref variant, ref value)| quote!(#value => ::core::result::Result::Ok(#ident::#variant)), + ); + let is_valid_doc = format!("Returns `true` if `value` is a variant of `{}`.", ident); let from_i32_doc = format!( "Converts an `i32` to a `{}`, or `None` if `value` is not a valid variant.", @@ -307,6 +327,7 @@ fn try_enumeration(input: TokenStream) -> Result { } } + #[deprecated = "Use the TryFrom implementation instead"] #[doc=#from_i32_doc] pub fn from_i32(value: i32) -> ::core::option::Option<#ident> { match value { @@ -327,6 +348,17 @@ fn try_enumeration(input: TokenStream) -> Result { value as i32 } } + + impl #impl_generics ::core::convert::TryFrom:: for #ident #ty_generics #where_clause { + type Error = ::prost::DecodeError; + + fn try_from(value: i32) -> ::core::result::Result<#ident, ::prost::DecodeError> { + match value { + #(#try_from,)* + _ => ::core::result::Result::Err(::prost::DecodeError::new("invalid enumeration value")), + } + } + } }; Ok(expanded.into()) @@ -342,6 +374,12 @@ fn try_oneof(input: TokenStream) -> Result { let ident = input.ident; + syn::custom_keyword!(skip_debug); + let skip_debug = input + .attrs + .into_iter() + .any(|a| a.path().is_ident("prost") && a.parse_args::().is_ok()); + let variants = match input.data { Data::Enum(DataEnum { variants, .. }) => variants, Data::Struct(..) => bail!("Oneof can not be derived for a struct"), @@ -424,16 +462,6 @@ fn try_oneof(input: TokenStream) -> Result { quote!(#ident::#variant_ident(ref value) => #encoded_len) }); - let debug = fields.iter().map(|&(ref variant_ident, ref field)| { - let wrapper = field.debug(quote!(*value)); - quote!(#ident::#variant_ident(ref value) => { - let wrapper = #wrapper; - f.debug_tuple(stringify!(#variant_ident)) - .field(&wrapper) - .finish() - }) - }); - let expanded = quote! { impl #impl_generics #ident #ty_generics #where_clause { /// Encodes the message to a buffer. @@ -467,10 +495,27 @@ fn try_oneof(input: TokenStream) -> Result { } } - impl #impl_generics ::core::fmt::Debug for #ident #ty_generics #where_clause { - fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - match *self { - #(#debug,)* + }; + let expanded = if skip_debug { + expanded + } else { + let debug = fields.iter().map(|&(ref variant_ident, ref field)| { + let wrapper = field.debug(quote!(*value)); + quote!(#ident::#variant_ident(ref value) => { + let wrapper = #wrapper; + f.debug_tuple(stringify!(#variant_ident)) + .field(&wrapper) + .finish() + }) + }); + quote! { + #expanded + + impl #impl_generics ::core::fmt::Debug for #ident #ty_generics #where_clause { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match *self { + #(#debug,)* + } } } } diff --git a/src/rust/vendor/prost/.cargo-checksum.json b/src/rust/vendor/prost/.cargo-checksum.json index 480793512..6daae80e0 100644 --- a/src/rust/vendor/prost/.cargo-checksum.json +++ b/src/rust/vendor/prost/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"183851a02065eed014bb2d63b45c15f4912e64552f82ce4c6b34a82bbd97b132","FUZZING.md":"90e5d9ae4cf3b975a7f917224cec20d5d757a9ca33e2bd6d3e2bb984409d3292","LICENSE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","README.md":"310f382a949d2af22e1ab4299b7b9c037f551790d4279df70d12c5822b790d86","benches/varint.rs":"25e28eadeb5092882281eaa16307ae72cbdabe04a308c9cfe15d3a62c8ead40b","clippy.toml":"10eea08f9e26e0dc498e431ac3a62b861bd74029d1cad8a394284af4cbc90532","flake.lock":"c0f731ad4db81f7f120a79a6dac4467970d410b9942688eb6286cd6f3e8c1f01","flake.nix":"8a0c3832f50cf2a134effaf269ae78189e5fcaae15de2a512f12685102217ef1","prepare-release.sh":"67f42e0649d33269c88272e69a9bf48d02de42126a9942ac6298b6995adea8df","publish-release.sh":"0cf0c6ec2765f19d45e271d005a6ad46f7b9b00241ba8a915ece8d100062546b","src/encoding.rs":"bcaeeecb90826f37dde6ee6c3d657ff4d69d6fe0e865e3a256665086d046400f","src/error.rs":"bfccee0fc06836f9b32b1cdb631237031d0ba8e1bc82548db3c4a6c10c06e784","src/lib.rs":"4475109102d73957b4bc18337551ca1da7c6b02896c9cb694d90692af480ba02","src/message.rs":"e4f85ffe6f0a66778b782199e29d450ec53a10e818e20199b15bb1d11d067521","src/types.rs":"edfefaf56ab4bc12c98cbcd9d0b3ca18c10352217556c193be6314990ecffd9c"},"package":"c01db6702aa05baa3f57dec92b8eeeeb4cb19e894e73996b32a4093289e54592"} \ No newline at end of file +{"files":{"Cargo.toml":"a3ac5fec4abcd9ef35ba4cb8924964a1158c1b2c48c70f87532aacbc5d34cbb2","FUZZING.md":"90e5d9ae4cf3b975a7f917224cec20d5d757a9ca33e2bd6d3e2bb984409d3292","KANI.md":"7dd64e21f8ade66b2b795042159f1163bfd304ff58172deb126fe788d71b2056","LICENSE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","README.md":"f76f54a5eda4a38e24d360db6370dde5172c07c117ddb92878c9a613c50c7c68","benches/varint.rs":"25e28eadeb5092882281eaa16307ae72cbdabe04a308c9cfe15d3a62c8ead40b","clippy.toml":"10eea08f9e26e0dc498e431ac3a62b861bd74029d1cad8a394284af4cbc90532","flake.lock":"c0f731ad4db81f7f120a79a6dac4467970d410b9942688eb6286cd6f3e8c1f01","flake.nix":"08f0e2ffcf522caa30399f3f540dc9c2fe46c9745ce76b45563118045cd4f4d1","prepare-release.sh":"67f42e0649d33269c88272e69a9bf48d02de42126a9942ac6298b6995adea8df","publish-release.sh":"0cf0c6ec2765f19d45e271d005a6ad46f7b9b00241ba8a915ece8d100062546b","src/encoding.rs":"bcaeeecb90826f37dde6ee6c3d657ff4d69d6fe0e865e3a256665086d046400f","src/error.rs":"bfccee0fc06836f9b32b1cdb631237031d0ba8e1bc82548db3c4a6c10c06e784","src/lib.rs":"df1534418dc88712e7d77f2cce7297fd9ff520d4a56e576dfbe38700f6fa254a","src/message.rs":"e4f85ffe6f0a66778b782199e29d450ec53a10e818e20199b15bb1d11d067521","src/name.rs":"ef5ac157cfeb195de60e0d5a3de00fe6e1d864182d557032841259049f72c173","src/types.rs":"edfefaf56ab4bc12c98cbcd9d0b3ca18c10352217556c193be6314990ecffd9c"},"package":"f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d"} \ No newline at end of file diff --git a/src/rust/vendor/prost/Cargo.toml b/src/rust/vendor/prost/Cargo.toml index bbe1ff922..612772978 100644 --- a/src/rust/vendor/prost/Cargo.toml +++ b/src/rust/vendor/prost/Cargo.toml @@ -11,9 +11,9 @@ [package] edition = "2021" -rust-version = "1.56" +rust-version = "1.60" name = "prost" -version = "0.11.5" +version = "0.12.1" authors = [ "Dan Burkert ", "Lucio Franco .cargo/config.toml + ``` + +**Please Note**: +- `features/proptest` branch under Kani is likely not the final + location for this code. If these instructions stop working, please + consult the Kani documentation and file an issue on [the Kani + repo](https://github.com/model-checking/kani.git). +- The cargo config file will force cargo to always use PropProof. To + use `proptest`, delete the file. + +## Running Kani +After installing Kani and PropProof, `cargo kani --tests` should +automatically run `proptest!` harnesses inside your crate. Use +`--harness` to run a specific harness, and `-p` for a specific +sub-crate. + +If Kani returns with an error, you can use the concrete playback +feature using `--enable-unstable --concrete-playback print` and paste +in the code to your repository. Running this harness with `cargo test` +will replay the input found by Kani that produced this crash. Please +note that this feature is unstable and using `--concrete-playback +inplace` to automatically inject a replay harness is not supported +when using PropProof. + +## Debugging CI Failure +```yaml + - name: Verify with Kani + uses: model-checking/kani-github-action@v0.xx + with: + enable-propproof: true + args: | + $KANI_ARGUMENTS +``` + +The above GitHub CI workflow is equivalent to `cargo kani +$KANI_ARGUMENTS` with PropProof installed. To replicate issues +locally, run `cargo kani` with the same arguments. diff --git a/src/rust/vendor/prost/README.md b/src/rust/vendor/prost/README.md index 5ebae13a2..88f4afaf1 100644 --- a/src/rust/vendor/prost/README.md +++ b/src/rust/vendor/prost/README.md @@ -30,9 +30,9 @@ First, add `prost` and its public dependencies to your `Cargo.toml`: ```ignore [dependencies] -prost = "0.11" +prost = "0.12" # Only necessary if using Protobuf well-known types: -prost-types = "0.11" +prost-types = "0.12" ``` The recommended way to add `.proto` compilation to a Cargo project is to use the @@ -44,7 +44,7 @@ start-to-finish example. ### MSRV -`prost` follows the `tokio-rs` projects MSRV model and supports 1.56+. For more +`prost` follows the `tokio-rs` projects MSRV model and supports 1.60. For more information on the tokio msrv policy you can check it out [here][tokio msrv] [tokio msrv]: https://github.com/tokio-rs/tokio/#supported-rust-versions @@ -62,7 +62,7 @@ With `prost-build` v0.11 release, `protoc` will be required to invoke bundled a `protoc` or attempt to compile `protoc` for users. For install instructions for `protoc` please check out the [protobuf install] instructions. -[protobuf install]: https://github.com/protocolbuffers/protobuf#protocol-compiler-installation +[protobuf install]: https://github.com/protocolbuffers/protobuf#protobuf-compiler-installation ### Packages @@ -163,21 +163,22 @@ The `#[derive(::prost::Enumeration)]` annotation added to the generated ```rust,ignore impl PhoneType { pub fn is_valid(value: i32) -> bool { ... } + #[deprecated] pub fn from_i32(value: i32) -> Option { ... } } ``` -so you can convert an `i32` to its corresponding `PhoneType` value by doing, +It also adds an `impl TryFrom for PhoneType`, so you can convert an `i32` to its corresponding `PhoneType` value by doing, for example: ```rust,ignore let phone_type = 2i32; -match PhoneType::from_i32(phone_type) { - Some(PhoneType::Mobile) => ..., - Some(PhoneType::Home) => ..., - Some(PhoneType::Work) => ..., - None => ..., +match PhoneType::try_from(phone_type) { + Ok(PhoneType::Mobile) => ..., + Ok(PhoneType::Home) => ..., + Ok(PhoneType::Work) => ..., + Err(_) => ..., } ``` diff --git a/src/rust/vendor/prost/flake.nix b/src/rust/vendor/prost/flake.nix index ac943ea47..a200020e3 100644 --- a/src/rust/vendor/prost/flake.nix +++ b/src/rust/vendor/prost/flake.nix @@ -14,7 +14,7 @@ { devShells.default = pkgs.mkShell { packages = with pkgs; [ cargo rustc ]; - buildInputs = with pkgs; [ pkg-config protobuf curl ]; + buildInputs = with pkgs; [ pkg-config protobuf curl cmake ninja ]; }; }); } diff --git a/src/rust/vendor/prost/src/lib.rs b/src/rust/vendor/prost/src/lib.rs index 999533173..9cc670087 100644 --- a/src/rust/vendor/prost/src/lib.rs +++ b/src/rust/vendor/prost/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/prost/0.11.5")] +#![doc(html_root_url = "https://docs.rs/prost/0.12.1")] #![cfg_attr(not(feature = "std"), no_std)] #![doc = include_str!("../README.md")] @@ -11,6 +11,7 @@ pub use bytes; mod error; mod message; +mod name; mod types; #[doc(hidden)] @@ -18,6 +19,7 @@ pub mod encoding; pub use crate::error::{DecodeError, EncodeError}; pub use crate::message::Message; +pub use crate::name::Name; use bytes::{Buf, BufMut}; diff --git a/src/rust/vendor/prost/src/name.rs b/src/rust/vendor/prost/src/name.rs new file mode 100644 index 000000000..1f94de6a7 --- /dev/null +++ b/src/rust/vendor/prost/src/name.rs @@ -0,0 +1,28 @@ +//! Support for associating type name information with a [`Message`]. + +use crate::Message; +use alloc::{format, string::String}; + +/// Associate a type name with a [`Message`] type. +pub trait Name: Message { + /// Type name for this [`Message`]. This is the camel case name, + /// e.g. `TypeName`. + const NAME: &'static str; + + /// Package name this message type is contained in. They are domain-like + /// and delimited by `.`, e.g. `google.protobuf`. + const PACKAGE: &'static str; + + /// Full name of this message type containing both the package name and + /// type name, e.g. `google.protobuf.TypeName`. + fn full_name() -> String { + format!("{}.{}", Self::NAME, Self::PACKAGE) + } + + /// Type URL for this message, which by default is the full name with a + /// leading slash, but may also include a leading domain name, e.g. + /// `type.googleapis.com/google.profile.Person`. + fn type_url() -> String { + format!("/{}", Self::full_name()) + } +} diff --git a/tools/prost-build-proto/Cargo.lock b/tools/prost-build-proto/Cargo.lock index d386c2675..c7726b075 100644 --- a/tools/prost-build-proto/Cargo.lock +++ b/tools/prost-build-proto/Cargo.lock @@ -3,16 +3,19 @@ version = 3 [[package]] -name = "anyhow" -version = "1.0.70" +name = "aho-corasick" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] [[package]] -name = "autocfg" -version = "1.1.0" +name = "anyhow" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "bitflags" @@ -21,16 +24,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "bytes" -version = "1.4.0" +name = "bitflags" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] -name = "cc" -version = "1.0.79" +name = "bytes" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cfg-if" @@ -40,39 +43,31 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] -name = "errno" -version = "0.2.8" +name = "equivalent" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] -name = "errno-dragonfly" -version = "0.1.2" +name = "errno" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ - "cc", "libc", + "windows-sys", ] [[package]] name = "fastrand" -version = "1.9.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fixedbitset" @@ -82,9 +77,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "hashbrown" -version = "0.12.3" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" [[package]] name = "heck" @@ -93,76 +88,56 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] -name = "hermit-abi" -version = "0.3.1" +name = "home" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" - -[[package]] -name = "indexmap" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "autocfg", - "hashbrown", + "windows-sys", ] [[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.9" +name = "indexmap" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.45.0", + "equivalent", + "hashbrown", ] [[package]] name = "itertools" -version = "0.10.5" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ "either", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" -version = "0.2.140" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "linux-raw-sys" -version = "0.1.4" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "log" -version = "0.4.17" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "multimap" @@ -172,15 +147,15 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "once_cell" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "petgraph" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", "indexmap", @@ -188,9 +163,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.1.25" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", "syn", @@ -198,18 +173,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] [[package]] name = "prost" -version = "0.11.8" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48e50df39172a3e7eb17e14642445da64996989bc212b583015435d39a58537" +checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" dependencies = [ "bytes", "prost-derive", @@ -217,16 +192,16 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.8" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c828f93f5ca4826f97fedcbd3f9a536c16b12cff3dbbb4a007f932bbad95b12" +checksum = "8bdf592881d821b83d471f8af290226c8d51402259e9bb5be7f9f8bdebbb11ac" dependencies = [ "bytes", "heck", "itertools", - "lazy_static", "log", "multimap", + "once_cell", "petgraph", "prettyplease", "prost", @@ -246,9 +221,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.11.8" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea9b0f8cbe5e15a8a042d030bd96668db28ecb567ec37d691971ff5731d2b1b" +checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" dependencies = [ "anyhow", "itertools", @@ -259,65 +234,78 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.11.8" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "379119666929a1afd7a043aa6cf96fa67a6dce9af60c88095a4686dbce4c9c88" +checksum = "e081b29f63d83a4bc75cfc9f3fe424f9156cf92d8a4f0c9407cce9a1b67327cf" dependencies = [ "prost", ] [[package]] name = "quote" -version = "1.0.26" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "regex" -version = "1.7.1" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rustix" -version = "0.36.11" +version = "0.38.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4165c9963ab29e422d6c26fbc1d37f15bace6b2810221f9d925023480fcf0e" +checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" dependencies = [ - "bitflags", + "bitflags 2.4.1", "errno", - "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.45.0", + "windows-sys", ] [[package]] name = "syn" -version = "1.0.109" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -326,85 +314,49 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.4.0" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" +checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", "fastrand", "redox_syscall", "rustix", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "which" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", - "libc", + "home", "once_cell", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "rustix", ] [[package]] name = "windows-sys" -version = "0.45.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -417,42 +369,42 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/tools/prost-build-proto/Cargo.toml b/tools/prost-build-proto/Cargo.toml index 38bc73d73..6ed006616 100644 --- a/tools/prost-build-proto/Cargo.toml +++ b/tools/prost-build-proto/Cargo.toml @@ -21,4 +21,4 @@ license = "Apache-2.0" [dependencies.prost-build] # keep version in sync with src/rust/bitbox02-rust/Cargo.toml -version = "0.11.5" +version = "0.12.1"