diff --git a/.ci/run-container-ci b/.ci/run-container-ci index e4fc7d238a..fb824f0a27 100755 --- a/.ci/run-container-ci +++ b/.ci/run-container-ci @@ -1,6 +1,6 @@ #!/bin/bash # Copyright 2019 Shift Cryptosecurity AG -# Copyright 2020 Shift Crypto AG +# Copyright 2020-2024 Shift Crypto AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ set -e set -x -CONTAINER=shiftcrypto/firmware_v2:39 +CONTAINER=shiftcrypto/firmware_v2:40 if [ "$1" == "pull" ] ; then docker pull "$CONTAINER" diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock index a8e48a1884..dcdeeb6fae 100644 --- a/src/rust/Cargo.lock +++ b/src/rust/Cargo.lock @@ -552,9 +552,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" +checksum = "e13db3d3fde688c61e2446b4d843bc27a7e8af269a69440c0308021dc92333cc" dependencies = [ "bytes", "prost-derive", @@ -562,9 +562,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" +checksum = "18bec9b0adc4eba778b33684b7ba3e7137789434769ee3ce3930463ef904cfca" dependencies = [ "anyhow", "itertools", diff --git a/src/rust/bitbox02-rust/Cargo.toml b/src/rust/bitbox02-rust/Cargo.toml index 7d3d9ff9eb..715f180bd0 100644 --- a/src/rust/bitbox02-rust/Cargo.toml +++ b/src/rust/bitbox02-rust/Cargo.toml @@ -58,9 +58,9 @@ bitcoin_hashes = { version = "0.14.0", default-features = false, features = ["sm [dependencies.prost] # keep version in sync with tools/prost-build/Cargo.toml. -version = "0.12.1" +version = "0.13.1" default-features = false -features = ["prost-derive"] +features = ["derive"] [features] ed25519 = [ diff --git a/src/rust/bitbox02-rust/src/hww/api/error.rs b/src/rust/bitbox02-rust/src/hww/api/error.rs index f210f63c91..81e22c0422 100644 --- a/src/rust/bitbox02-rust/src/hww/api/error.rs +++ b/src/rust/bitbox02-rust/src/hww/api/error.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Shift Crypto AG +// Copyright 2020-2024 Shift Crypto AG // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -113,8 +113,8 @@ impl core::convert::From for Error { } } -impl core::convert::From for Error { - fn from(_error: prost::DecodeError) -> Self { +impl core::convert::From for Error { + fn from(_error: prost::UnknownEnumValue) -> Self { Error::InvalidInput } } diff --git a/src/rust/rust-toolchain.toml b/src/rust/rust-toolchain.toml index 628740b12f..4d2dee853e 100644 --- a/src/rust/rust-toolchain.toml +++ b/src/rust/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.79.0" +channel = "1.80.0" diff --git a/src/rust/vendor/bip32-ed25519/.cargo-checksum.json b/src/rust/vendor/bip32-ed25519/.cargo-checksum.json index 4bf565202c..860878bcf0 100644 --- a/src/rust/vendor/bip32-ed25519/.cargo-checksum.json +++ b/src/rust/vendor/bip32-ed25519/.cargo-checksum.json @@ -1 +1 @@ -{"files":{".github/workflows/ci.yml":"f465a052857e00c4a513784ae8527fca34a9a0b1075c7511bbf302b96d6e9e36","Cargo.toml":"4f133fb93e1cfba99cee3a46432e4927593e4a88d24594b4b62d15c5922c5a34","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"5530596cde343de2238ec3276d94599ff6e78b7b7a20f6143162b3eceb727f29","README.md":"99a18dfc2a588d8b8cb3c287dad52d2e76c2b2b3be0e7a95cce19f509e9d59d7","src/arbitrary.rs":"ecb52788eec1142459ab252c320a5f0e421eb63cf959260b16e689ccfc8f2590","src/bigint.rs":"756b33c8d971b282b43268671c08fb4d8af095a6ebb6e9dc0c750631650e4d14","src/lib.rs":"93a19d865e85bde9646e42ef6c6b5106d6876c71fcffedad4b2c523deeb6f951","tests/table_test.rs":"7cba52f2578cfaf44f7d01a14ae1ce3b2b21857079722b7f04a507ca2884d878","tests/testdata/gen_table.py":"2fd91055920d9ac4cfb6c004b96aca42aaf2e3cf074d0d49d48ada993abdaedf","tests/testdata/table.json":"9e37a43d759f793b091f87488ea4b6d733154a10d29554c5103e12d617ae70cd"},"package":null} \ No newline at end of file +{"files":{".github/workflows/ci.yml":"f465a052857e00c4a513784ae8527fca34a9a0b1075c7511bbf302b96d6e9e36","Cargo.toml":"0a34a4a982d9e6dca40bd70859a657f9ed430cae3baf928157cc2cd07aa6e0b1","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"5530596cde343de2238ec3276d94599ff6e78b7b7a20f6143162b3eceb727f29","README.md":"99a18dfc2a588d8b8cb3c287dad52d2e76c2b2b3be0e7a95cce19f509e9d59d7","src/arbitrary.rs":"ecb52788eec1142459ab252c320a5f0e421eb63cf959260b16e689ccfc8f2590","src/bigint.rs":"756b33c8d971b282b43268671c08fb4d8af095a6ebb6e9dc0c750631650e4d14","src/lib.rs":"93a19d865e85bde9646e42ef6c6b5106d6876c71fcffedad4b2c523deeb6f951","tests/table_test.rs":"7cba52f2578cfaf44f7d01a14ae1ce3b2b21857079722b7f04a507ca2884d878","tests/testdata/gen_table.py":"2fd91055920d9ac4cfb6c004b96aca42aaf2e3cf074d0d49d48ada993abdaedf","tests/testdata/table.json":"9e37a43d759f793b091f87488ea4b6d733154a10d29554c5103e12d617ae70cd"},"package":null} \ No newline at end of file diff --git a/src/rust/vendor/bip32-ed25519/Cargo.toml b/src/rust/vendor/bip32-ed25519/Cargo.toml index 4a642a64c7..d98f4bbe04 100644 --- a/src/rust/vendor/bip32-ed25519/Cargo.toml +++ b/src/rust/vendor/bip32-ed25519/Cargo.toml @@ -9,11 +9,20 @@ # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. +bin = [] +example = [] +bench = [] + [package] edition = "2021" name = "bip32-ed25519" version = "0.2.0" authors = ["Shift Crypto AG "] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "BIP32-Ed25519" readme = "README.md" keywords = ["no_std"] @@ -23,6 +32,14 @@ categories = [ ] license = "MIT OR Apache-2.0" +[lib] +name = "bip32_ed25519" +path = "src/lib.rs" + +[[test]] +name = "table_test" +path = "tests/table_test.rs" + [dependencies.curve25519-dalek] version = "4" default-features = false diff --git a/src/rust/vendor/prost-derive/.cargo-checksum.json b/src/rust/vendor/prost-derive/.cargo-checksum.json index 3fc2ef84e1..854780b15e 100644 --- a/src/rust/vendor/prost-derive/.cargo-checksum.json +++ b/src/rust/vendor/prost-derive/.cargo-checksum.json @@ -1 +1 @@ -{"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 +{"files":{"Cargo.toml":"ead70d2c5042f3983e63d28a5056647d2606e29366a6e3f3ab6e659376c3ddd6","LICENSE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","README.md":"6c67fa1e48f14adfaf834f520f798ddfb79f90804f46cc215ee391a7d57913a4","src/field/group.rs":"0e2a468af54d9082d858f18d5276fd549349f0048d9aaf41a3493018a811d962","src/field/map.rs":"a03791fc758802cdf4e75e197acd7975141377e3d1ad1273e6cefab2b7fddfe9","src/field/message.rs":"736e160b4e470dc6d0f2fcbf12e704c590bc1880e5fe08933c440f1cf2e767b1","src/field/mod.rs":"541c1a346a0ff4fcb4610a5c9d379e99a7dbfe8981e5c1c902ddf6c395dfda0a","src/field/oneof.rs":"c0a55cb194d9651cbc63c2a19243a7e5fc197c170a9f44af87b30b07bad21b4e","src/field/scalar.rs":"61150549be0de070845018ae5aef8c42bebdae033e4e251bddbd0bd2a892c501","src/lib.rs":"a3e62b31b0e72438b41a8a2e69241640ace46b95936c4f93269bf650386e3c59"},"package":"18bec9b0adc4eba778b33684b7ba3e7137789434769ee3ce3930463ef904cfca"} \ 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 768b03f289..48fa5ab29f 100644 --- a/src/rust/vendor/prost-derive/Cargo.toml +++ b/src/rust/vendor/prost-derive/Cargo.toml @@ -11,16 +11,16 @@ [package] edition = "2021" -rust-version = "1.60" +rust-version = "1.70" name = "prost-derive" -version = "0.12.1" +version = "0.13.1" authors = [ "Dan Burkert ", "Lucio Franco ", + "Casper Meijn ", "Tokio Contributors ", ] -description = "A Protocol Buffers implementation for the Rust Language." -documentation = "https://docs.rs/prost-derive" +description = "Generate encoding and decoding implementations for Prost annotated types." readme = "README.md" license = "Apache-2.0" repository = "https://github.com/tokio-rs/prost" @@ -32,12 +32,10 @@ proc_macro = true version = "1.0.1" [dependencies.itertools] -version = ">=0.10, <0.12" -features = ["use_alloc"] -default-features = false +version = ">=0.10.1, <=0.13" [dependencies.proc-macro2] -version = "1" +version = "1.0.60" [dependencies.quote] version = "1" diff --git a/src/rust/vendor/prost-derive/src/field/group.rs b/src/rust/vendor/prost-derive/src/field/group.rs index 076b577d73..485ecfc1bf 100644 --- a/src/rust/vendor/prost-derive/src/field/group.rs +++ b/src/rust/vendor/prost-derive/src/field/group.rs @@ -38,10 +38,11 @@ impl Field { return Ok(None); } - match unknown_attrs.len() { - 0 => (), - 1 => bail!("unknown attribute for group field: {:?}", unknown_attrs[0]), - _ => bail!("unknown attributes for group field: {:?}", unknown_attrs), + if !unknown_attrs.is_empty() { + bail!( + "unknown attribute(s) for group field: #[prost({})]", + quote!(#(#unknown_attrs),*) + ); } let tag = match tag.or(inferred_tag) { diff --git a/src/rust/vendor/prost-derive/src/field/message.rs b/src/rust/vendor/prost-derive/src/field/message.rs index 3bcdddfb16..f6ac391e73 100644 --- a/src/rust/vendor/prost-derive/src/field/message.rs +++ b/src/rust/vendor/prost-derive/src/field/message.rs @@ -38,13 +38,11 @@ impl Field { return Ok(None); } - match unknown_attrs.len() { - 0 => (), - 1 => bail!( - "unknown attribute for message field: {:?}", - unknown_attrs[0] - ), - _ => bail!("unknown attributes for message field: {:?}", unknown_attrs), + if !unknown_attrs.is_empty() { + bail!( + "unknown attribute(s) for message field: #[prost({})]", + quote!(#(#unknown_attrs),*) + ); } let tag = match tag.or(inferred_tag) { diff --git a/src/rust/vendor/prost-derive/src/field/mod.rs b/src/rust/vendor/prost-derive/src/field/mod.rs index 4bec5617c2..366075e451 100644 --- a/src/rust/vendor/prost-derive/src/field/mod.rs +++ b/src/rust/vendor/prost-derive/src/field/mod.rs @@ -269,9 +269,7 @@ fn bool_attr(key: &str, attr: &Meta) -> Result, Error> { } match *attr { Meta::Path(..) => Ok(Some(true)), - Meta::List(ref meta_list) => { - return Ok(Some(meta_list.parse_args::()?.value())); - } + Meta::List(ref meta_list) => Ok(Some(meta_list.parse_args::()?.value())), Meta::NameValue(MetaNameValue { value: Expr::Lit(ExprLit { @@ -310,9 +308,7 @@ pub(super) fn tag_attr(attr: &Meta) -> Result, Error> { return Ok(None); } match *attr { - Meta::List(ref meta_list) => { - return Ok(Some(meta_list.parse_args::()?.base10_parse()?)); - } + Meta::List(ref meta_list) => Ok(Some(meta_list.parse_args::()?.base10_parse()?)), Meta::NameValue(MetaNameValue { value: Expr::Lit(ref expr), .. diff --git a/src/rust/vendor/prost-derive/src/field/oneof.rs b/src/rust/vendor/prost-derive/src/field/oneof.rs index 78c77eeb13..ad1e32f19a 100644 --- a/src/rust/vendor/prost-derive/src/field/oneof.rs +++ b/src/rust/vendor/prost-derive/src/field/oneof.rs @@ -44,13 +44,11 @@ impl Field { None => return Ok(None), }; - match unknown_attrs.len() { - 0 => (), - 1 => bail!( - "unknown attribute for message field: {:?}", - unknown_attrs[0] - ), - _ => bail!("unknown attributes for message field: {:?}", unknown_attrs), + if !unknown_attrs.is_empty() { + bail!( + "unknown attribute(s) for message field: #[prost({})]", + quote!(#(#unknown_attrs),*) + ); } let tags = match tags { diff --git a/src/rust/vendor/prost-derive/src/field/scalar.rs b/src/rust/vendor/prost-derive/src/field/scalar.rs index 5a3dfb2ec3..c2e870524d 100644 --- a/src/rust/vendor/prost-derive/src/field/scalar.rs +++ b/src/rust/vendor/prost-derive/src/field/scalar.rs @@ -1,4 +1,3 @@ -use std::convert::TryFrom; use std::fmt; use anyhow::{anyhow, bail, Error}; @@ -47,10 +46,11 @@ impl Field { None => return Ok(None), }; - match unknown_attrs.len() { - 0 => (), - 1 => bail!("unknown attribute: {:?}", unknown_attrs[0]), - _ => bail!("unknown attributes: {:?}", unknown_attrs), + if !unknown_attrs.is_empty() { + bail!( + "unknown attribute(s): #[prost({})]", + quote!(#(#unknown_attrs),*) + ); } let tag = match tag.or(inferred_tag) { @@ -272,7 +272,7 @@ impl Field { pub fn methods(&self, ident: &TokenStream) -> Option { let mut ident_str = ident.to_string(); if ident_str.starts_with("r#") { - ident_str = ident_str[2..].to_owned(); + ident_str = ident_str.split_off(2); } // Prepend `get_` for getter methods of tuple structs. diff --git a/src/rust/vendor/prost-derive/src/lib.rs b/src/rust/vendor/prost-derive/src/lib.rs index 8bc99c5eda..789ea2c5bf 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.12.1")] +#![doc(html_root_url = "https://docs.rs/prost-derive/0.13.1")] // The `quote!` macro requires deep recursion. #![recursion_limit = "4096"] @@ -7,8 +7,7 @@ extern crate proc_macro; use anyhow::{bail, Error}; use itertools::Itertools; -use proc_macro::TokenStream; -use proc_macro2::Span; +use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::{ punctuated::Punctuated, Data, DataEnum, DataStruct, DeriveInput, Expr, Fields, FieldsNamed, @@ -19,7 +18,7 @@ mod field; use crate::field::Field; fn try_message(input: TokenStream) -> Result { - let input: DeriveInput = syn::parse(input)?; + let input: DeriveInput = syn::parse2(input)?; let ident = input.ident; @@ -88,29 +87,31 @@ fn try_message(input: TokenStream) -> Result { // TODO: This encodes oneof fields in the position of their lowest tag, // regardless of the currently occupied variant, is that consequential? // See: https://developers.google.com/protocol-buffers/docs/encoding#order - fields.sort_by_key(|&(_, ref field)| field.tags().into_iter().min().unwrap()); + fields.sort_by_key(|(_, field)| field.tags().into_iter().min().unwrap()); let fields = fields; - let mut tags = fields + if let Some(duplicate_tag) = fields .iter() - .flat_map(|&(_, ref field)| field.tags()) - .collect::>(); - let num_tags = tags.len(); - tags.sort_unstable(); - tags.dedup(); - if tags.len() != num_tags { - bail!("message {} has fields with duplicate tags", ident); - } + .flat_map(|(_, field)| field.tags()) + .duplicates() + .next() + { + bail!( + "message {} has multiple fields with tag {}", + ident, + duplicate_tag + ) + }; let encoded_len = fields .iter() - .map(|&(ref field_ident, ref field)| field.encoded_len(quote!(self.#field_ident))); + .map(|(field_ident, field)| field.encoded_len(quote!(self.#field_ident))); let encode = fields .iter() - .map(|&(ref field_ident, ref field)| field.encode(quote!(self.#field_ident))); + .map(|(field_ident, field)| field.encode(quote!(self.#field_ident))); - let merge = fields.iter().map(|&(ref field_ident, ref field)| { + let merge = fields.iter().map(|(field_ident, field)| { let merge = field.merge(quote!(value)); let tags = field.tags().into_iter().map(|tag| quote!(#tag)); let tags = Itertools::intersperse(tags, quote!(|)); @@ -136,7 +137,7 @@ fn try_message(input: TokenStream) -> Result { let clear = fields .iter() - .map(|&(ref field_ident, ref field)| field.clear(quote!(self.#field_ident))); + .map(|(field_ident, field)| field.clear(quote!(self.#field_ident))); let default = if is_struct { let default = fields.iter().map(|(field_ident, field)| { @@ -158,7 +159,7 @@ fn try_message(input: TokenStream) -> Result { let methods = fields .iter() - .flat_map(|&(ref field_ident, ref field)| field.methods(field_ident)) + .flat_map(|(field_ident, field)| field.methods(field_ident)) .collect::>(); let methods = if methods.is_empty() { quote!() @@ -174,19 +175,19 @@ fn try_message(input: TokenStream) -> Result { let expanded = quote! { impl #impl_generics ::prost::Message for #ident #ty_generics #where_clause { #[allow(unused_variables)] - fn encode_raw(&self, buf: &mut B) where B: ::prost::bytes::BufMut { + fn encode_raw(&self, buf: &mut impl ::prost::bytes::BufMut) { #(#encode)* } #[allow(unused_variables)] - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: ::prost::encoding::WireType, - buf: &mut B, + buf: &mut impl ::prost::bytes::Buf, ctx: ::prost::encoding::DecodeContext, ) -> ::core::result::Result<(), ::prost::DecodeError> - where B: ::prost::bytes::Buf { + { #struct_name match tag { #(#merge)* @@ -213,7 +214,7 @@ fn try_message(input: TokenStream) -> Result { let expanded = if skip_debug { expanded } else { - let debugs = unsorted_fields.iter().map(|&(ref field_ident, ref field)| { + let debugs = unsorted_fields.iter().map(|(field_ident, field)| { let wrapper = field.debug(quote!(self.#field_ident)); let call = if is_struct { quote!(builder.field(stringify!(#field_ident), &wrapper)) @@ -251,16 +252,16 @@ fn try_message(input: TokenStream) -> Result { #methods }; - Ok(expanded.into()) + Ok(expanded) } #[proc_macro_derive(Message, attributes(prost))] -pub fn message(input: TokenStream) -> TokenStream { - try_message(input).unwrap() +pub fn message(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + try_message(input.into()).unwrap().into() } fn try_enumeration(input: TokenStream) -> Result { - let input: DeriveInput = syn::parse(input)?; + let input: DeriveInput = syn::parse2(input)?; let ident = input.ident; let generics = &input.generics; @@ -300,16 +301,14 @@ fn try_enumeration(input: TokenStream) -> Result { let default = variants[0].0.clone(); - let is_valid = variants + let is_valid = variants.iter().map(|(_, value)| quote!(#value => true)); + let from = variants .iter() - .map(|&(_, ref value)| quote!(#value => true)); - let from = variants.iter().map( - |&(ref variant, ref value)| quote!(#value => ::core::option::Option::Some(#ident::#variant)), - ); + .map(|(variant, 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 try_from = variants + .iter() + .map(|(variant, 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!( @@ -350,27 +349,27 @@ fn try_enumeration(input: TokenStream) -> Result { } impl #impl_generics ::core::convert::TryFrom:: for #ident #ty_generics #where_clause { - type Error = ::prost::DecodeError; + type Error = ::prost::UnknownEnumValue; - fn try_from(value: i32) -> ::core::result::Result<#ident, ::prost::DecodeError> { + fn try_from(value: i32) -> ::core::result::Result<#ident, ::prost::UnknownEnumValue> { match value { #(#try_from,)* - _ => ::core::result::Result::Err(::prost::DecodeError::new("invalid enumeration value")), + _ => ::core::result::Result::Err(::prost::UnknownEnumValue(value)), } } } }; - Ok(expanded.into()) + Ok(expanded) } #[proc_macro_derive(Enumeration, attributes(prost))] -pub fn enumeration(input: TokenStream) -> TokenStream { - try_enumeration(input).unwrap() +pub fn enumeration(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + try_enumeration(input.into()).unwrap().into() } fn try_oneof(input: TokenStream) -> Result { - let input: DeriveInput = syn::parse(input)?; + let input: DeriveInput = syn::parse2(input)?; let ident = input.ident; @@ -414,31 +413,29 @@ fn try_oneof(input: TokenStream) -> Result { } } - let mut tags = fields + // Oneof variants cannot be oneofs themselves, so it's impossible to have a field with multiple + // tags. + assert!(fields.iter().all(|(_, field)| field.tags().len() == 1)); + + if let Some(duplicate_tag) = fields .iter() - .flat_map(|&(ref variant_ident, ref field)| -> Result { - if field.tags().len() > 1 { - bail!( - "invalid oneof variant {}::{}: oneof variants may only have a single tag", - ident, - variant_ident - ); - } - Ok(field.tags()[0]) - }) - .collect::>(); - tags.sort_unstable(); - tags.dedup(); - if tags.len() != fields.len() { - panic!("invalid oneof {}: variants have duplicate tags", ident); + .flat_map(|(_, field)| field.tags()) + .duplicates() + .next() + { + bail!( + "invalid oneof {}: multiple variants have tag {}", + ident, + duplicate_tag + ); } - let encode = fields.iter().map(|&(ref variant_ident, ref field)| { + let encode = fields.iter().map(|(variant_ident, field)| { let encode = field.encode(quote!(*value)); quote!(#ident::#variant_ident(ref value) => { #encode }) }); - let merge = fields.iter().map(|&(ref variant_ident, ref field)| { + let merge = fields.iter().map(|(variant_ident, field)| { let tag = field.tags()[0]; let merge = field.merge(quote!(value)); quote! { @@ -457,7 +454,7 @@ fn try_oneof(input: TokenStream) -> Result { } }); - let encoded_len = fields.iter().map(|&(ref variant_ident, ref field)| { + let encoded_len = fields.iter().map(|(variant_ident, field)| { let encoded_len = field.encoded_len(quote!(*value)); quote!(#ident::#variant_ident(ref value) => #encoded_len) }); @@ -465,21 +462,21 @@ fn try_oneof(input: TokenStream) -> Result { let expanded = quote! { impl #impl_generics #ident #ty_generics #where_clause { /// Encodes the message to a buffer. - pub fn encode(&self, buf: &mut B) where B: ::prost::bytes::BufMut { + pub fn encode(&self, buf: &mut impl ::prost::bytes::BufMut) { match *self { #(#encode,)* } } /// Decodes an instance of the message from a buffer, and merges it into self. - pub fn merge( + pub fn merge( field: &mut ::core::option::Option<#ident #ty_generics>, tag: u32, wire_type: ::prost::encoding::WireType, - buf: &mut B, + buf: &mut impl ::prost::bytes::Buf, ctx: ::prost::encoding::DecodeContext, ) -> ::core::result::Result<(), ::prost::DecodeError> - where B: ::prost::bytes::Buf { + { match tag { #(#merge,)* _ => unreachable!(concat!("invalid ", stringify!(#ident), " tag: {}"), tag), @@ -499,7 +496,7 @@ fn try_oneof(input: TokenStream) -> Result { let expanded = if skip_debug { expanded } else { - let debug = fields.iter().map(|&(ref variant_ident, ref field)| { + let debug = fields.iter().map(|(variant_ident, field)| { let wrapper = field.debug(quote!(*value)); quote!(#ident::#variant_ident(ref value) => { let wrapper = #wrapper; @@ -521,10 +518,99 @@ fn try_oneof(input: TokenStream) -> Result { } }; - Ok(expanded.into()) + Ok(expanded) } #[proc_macro_derive(Oneof, attributes(prost))] -pub fn oneof(input: TokenStream) -> TokenStream { - try_oneof(input).unwrap() +pub fn oneof(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + try_oneof(input.into()).unwrap().into() +} + +#[cfg(test)] +mod test { + use crate::{try_message, try_oneof}; + use quote::quote; + + #[test] + fn test_rejects_colliding_message_fields() { + let output = try_message(quote!( + struct Invalid { + #[prost(bool, tag = "1")] + a: bool, + #[prost(oneof = "super::Whatever", tags = "4, 5, 1")] + b: Option, + } + )); + assert_eq!( + output + .expect_err("did not reject colliding message fields") + .to_string(), + "message Invalid has multiple fields with tag 1" + ); + } + + #[test] + fn test_rejects_colliding_oneof_variants() { + let output = try_oneof(quote!( + pub enum Invalid { + #[prost(bool, tag = "1")] + A(bool), + #[prost(bool, tag = "3")] + B(bool), + #[prost(bool, tag = "1")] + C(bool), + } + )); + assert_eq!( + output + .expect_err("did not reject colliding oneof variants") + .to_string(), + "invalid oneof Invalid: multiple variants have tag 1" + ); + } + + #[test] + fn test_rejects_multiple_tags_oneof_variant() { + let output = try_oneof(quote!( + enum What { + #[prost(bool, tag = "1", tag = "2")] + A(bool), + } + )); + assert_eq!( + output + .expect_err("did not reject multiple tags on oneof variant") + .to_string(), + "duplicate tag attributes: 1 and 2" + ); + + let output = try_oneof(quote!( + enum What { + #[prost(bool, tag = "3")] + #[prost(tag = "4")] + A(bool), + } + )); + assert!(output.is_err()); + assert_eq!( + output + .expect_err("did not reject multiple tags on oneof variant") + .to_string(), + "duplicate tag attributes: 3 and 4" + ); + + let output = try_oneof(quote!( + enum What { + #[prost(bool, tags = "5,6")] + A(bool), + } + )); + assert!(output.is_err()); + assert_eq!( + output + .expect_err("did not reject multiple tags on oneof variant") + .to_string(), + "unknown attribute(s): #[prost(tags = \"5,6\")]" + ); + } } diff --git a/src/rust/vendor/prost/.cargo-checksum.json b/src/rust/vendor/prost/.cargo-checksum.json index 6daae80e01..eedff4d9b2 100644 --- a/src/rust/vendor/prost/.cargo-checksum.json +++ b/src/rust/vendor/prost/.cargo-checksum.json @@ -1 +1 @@ -{"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 +{"files":{"Cargo.toml":"1fbba13d18616dbf70e2b6dc138eeb150c1fdedc69bb9d0241d78db0a51b196a","LICENSE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","README.md":"606dccfcabd1797578a542e45f40df0ae37a42e53edd9df4c8c050653e586787","benches/varint.rs":"25e28eadeb5092882281eaa16307ae72cbdabe04a308c9cfe15d3a62c8ead40b","src/encoding.rs":"df60b41c214362063540a2bb65560c9c17eea071279b87e582cf35c200cb0da3","src/error.rs":"f0549601c38d34ee8c32dd5567bc2722d09b8cafe533da0d2124d5fd32cc0d6e","src/lib.rs":"9aa005356c2c5a384be5b3d3a3e721cee598f7f3760ed88765b4127eb79ce2ff","src/message.rs":"71de498c10c7d60c7732cb17f7e614158953a1ff249f52273b094b9afbf857f4","src/name.rs":"4524233d6c1a85ca55ce54d9740e72ecbb05714b558e8a77346c0a125a2e5320","src/types.rs":"908f5000fa83058e82e25f2041e8dc522d46961668cf703ba5446cd1964e3545"},"package":"e13db3d3fde688c61e2446b4d843bc27a7e8af269a69440c0308021dc92333cc"} \ No newline at end of file diff --git a/src/rust/vendor/prost/Cargo.toml b/src/rust/vendor/prost/Cargo.toml index 6127729788..e283b796a9 100644 --- a/src/rust/vendor/prost/Cargo.toml +++ b/src/rust/vendor/prost/Cargo.toml @@ -11,16 +11,16 @@ [package] edition = "2021" -rust-version = "1.60" +rust-version = "1.70" name = "prost" -version = "0.12.1" +version = "0.13.1" authors = [ "Dan Burkert ", - "Lucio Franco ", + "Casper Meijn ", "Tokio Contributors ", ] description = "A Protocol Buffers implementation for the Rust Language." -documentation = "https://docs.rs/prost" readme = "README.md" keywords = [ "protobuf", @@ -30,9 +30,6 @@ categories = ["encoding"] license = "Apache-2.0" repository = "https://github.com/tokio-rs/prost" -[profile.bench] -debug = 2 - [lib] bench = false @@ -45,20 +42,13 @@ version = "1" default-features = false [dependencies.prost-derive] -version = "0.12.1" +version = "0.13.1" optional = true [dev-dependencies.criterion] -version = "0.4" -default-features = false - -[dev-dependencies.env_logger] -version = "0.10" +version = "0.5" default-features = false -[dev-dependencies.log] -version = "0.4" - [dev-dependencies.proptest] version = "1" @@ -67,8 +57,10 @@ version = "0.8" [features] default = [ - "prost-derive", + "derive", "std", ] +derive = ["dep:prost-derive"] no-recursion-limit = [] +prost-derive = ["derive"] std = [] diff --git a/src/rust/vendor/prost/FUZZING.md b/src/rust/vendor/prost/FUZZING.md deleted file mode 100644 index b79112d04e..0000000000 --- a/src/rust/vendor/prost/FUZZING.md +++ /dev/null @@ -1,27 +0,0 @@ -# Fuzzing - -Prost ships a few fuzz tests, using both libfuzzer and aflfuzz. - - -## afl - -To run the afl fuzz tests, first install cargo-afl: - - cargo install -f afl - -Then build a fuzz target and run afl on it: - - cd fuzz/afl// - cargo afl build --bin fuzz-target - cargo afl fuzz -i in -o out target/debug/fuzz-target - -To reproduce a crash: - - cd fuzz/afl// - cargo build --bin reproduce - cargo run --bin reproduce -- out/crashes/ - - -## libfuzzer - -TODO diff --git a/src/rust/vendor/prost/KANI.md b/src/rust/vendor/prost/KANI.md deleted file mode 100644 index cafb0131d3..0000000000 --- a/src/rust/vendor/prost/KANI.md +++ /dev/null @@ -1,69 +0,0 @@ -# Kani -This document describes how to **locally** install and use Kani, along -with its experimental PropProof feature. Because of instability in -Kani internals, the GitHub action is the recommended option if you are -running in CI. - -Kani is a software verification tool that complements testing by -proving the absence of certain classes of bugs like unwrap exceptions, -overflows, and assertion failures. See the [Kani -book](https://model-checking.github.io/kani/) for a full list of -capabilities and limitations. - -## Installing Kani and PropProof -- The install instructions for Kani can be [found - here](https://model-checking.github.io/kani/install-guide.html). Once - Kani is installed, you can run with `cargo kani` for projects or - `kani` for individual Rust files. -- **[UNSTABLE]** To use PropProof, first download the source code - from the Kani repository. - ```bash - git clone https://github.com/model-checking/kani.git --branch features/proptest propproof - cd propproof; git submodule update --init - ``` - - Then, use `.cargo/config.toml` enable it in the local directory you - want to run Kani in. This will override the `proptest` import in - your repo. - - ```bash - cd $YOUR_REPO_LOCAL_PATH - mkdir '.cargo' - echo "paths =[\"$PATH_TO_PROPPROOF\"]" > .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 88f4afaf1d..5b903b6de8 100644 --- a/src/rust/vendor/prost/README.md +++ b/src/rust/vendor/prost/README.md @@ -1,4 +1,4 @@ -![continuous integration](https://github.com/tokio-rs/prost/workflows/continuous%20integration/badge.svg) +[![continuous integration](https://github.com/tokio-rs/prost/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/tokio-rs/prost/actions/workflows/ci.yml?query=branch%3Amaster) [![Documentation](https://docs.rs/prost/badge.svg)](https://docs.rs/prost/) [![Crate](https://img.shields.io/crates/v/prost.svg)](https://crates.io/crates/prost) [![Dependency Status](https://deps.rs/repo/github/tokio-rs/prost/status.svg)](https://deps.rs/repo/github/tokio-rs/prost) @@ -30,21 +30,23 @@ First, add `prost` and its public dependencies to your `Cargo.toml`: ```ignore [dependencies] -prost = "0.12" +prost = "0.13" # Only necessary if using Protobuf well-known types: -prost-types = "0.12" +prost-types = "0.13" ``` The recommended way to add `.proto` compilation to a Cargo project is to use the -`prost-build` library. See the [`prost-build` documentation](prost-build) for +`prost-build` library. See the [`prost-build` documentation][prost-build] for more details and examples. -See the [snazzy repository](https://github.com/danburkert/snazzy) for a simple -start-to-finish example. +See the [snazzy repository][snazzy] for a simple start-to-finish example. + +[prost-build]: https://docs.rs/prost-build/latest/prost_build/ +[snazzy]: https://github.com/danburkert/snazzy ### MSRV -`prost` follows the `tokio-rs` projects MSRV model and supports 1.60. For more +`prost` follows the `tokio-rs` project's MSRV model and supports 1.70. 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 @@ -59,8 +61,8 @@ possible. With `prost-build` v0.11 release, `protoc` will be required to invoke `compile_protos` (unless `skip_protoc` is enabled). Prost will no longer provide -bundled a `protoc` or attempt to compile `protoc` for users. For install -instructions for `protoc` please check out the [protobuf install] instructions. +bundled `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#protobuf-compiler-installation @@ -378,9 +380,9 @@ the `std` features in `prost` and `prost-types`: ```ignore [dependencies] -prost = { version = "0.6", default-features = false, features = ["prost-derive"] } +prost = { version = "0.13.1", default-features = false, features = ["prost-derive"] } # Only necessary if using Protobuf well-known types: -prost-types = { version = "0.6", default-features = false } +prost-types = { version = "0.13.1", default-features = false } ``` Additionally, configure `prost-build` to output `BTreeMap`s instead of `HashMap`s @@ -461,6 +463,11 @@ The prost project maintains flakes support for local development. Once you have nix and nix flakes setup you can just run `nix develop` to get a shell configured with the required dependencies to compile the whole project. +## Feature Flags +- `std`: Enable integration with standard library. Disable this feature for `no_std` support. This feature is enabled by default. +- `derive`: Enable integration with `prost-derive`. Disable this feature to reduce compile times. This feature is enabled by default. +- `prost-derive`: Deprecated. Alias for `derive` feature. +- `no-recursion-limit`: Disable the recursion limit. The recursion limit is 100 and cannot be customized. ## FAQ diff --git a/src/rust/vendor/prost/clippy.toml b/src/rust/vendor/prost/clippy.toml deleted file mode 100644 index 5988e12d8f..0000000000 --- a/src/rust/vendor/prost/clippy.toml +++ /dev/null @@ -1 +0,0 @@ -too-many-arguments-threshold=8 diff --git a/src/rust/vendor/prost/flake.lock b/src/rust/vendor/prost/flake.lock deleted file mode 100644 index 5cb2e9ea61..0000000000 --- a/src/rust/vendor/prost/flake.lock +++ /dev/null @@ -1,43 +0,0 @@ -{ - "nodes": { - "flake-utils": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1667969101, - "narHash": "sha256-GL53T705HO7Q/KVfbb5STx8AxFs8YgaGY8pvAZC+O7U=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "bbf77421ac51a7c93f5f0f760da99e4dbce614fa", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/src/rust/vendor/prost/flake.nix b/src/rust/vendor/prost/flake.nix deleted file mode 100644 index a200020e38..0000000000 --- a/src/rust/vendor/prost/flake.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ - description = "Prost dependencies"; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - flake-utils.url = "github:numtide/flake-utils"; - }; - - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { inherit system; }; - in - { - devShells.default = pkgs.mkShell { - packages = with pkgs; [ cargo rustc ]; - buildInputs = with pkgs; [ pkg-config protobuf curl cmake ninja ]; - }; - }); -} diff --git a/src/rust/vendor/prost/prepare-release.sh b/src/rust/vendor/prost/prepare-release.sh deleted file mode 100755 index 34e5202c24..0000000000 --- a/src/rust/vendor/prost/prepare-release.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# Script which automates modifying source version fields, and creating a release -# commit and tag. The commit and tag are not automatically pushed, nor are the -# crates published (see publish-release.sh). - -set -ex - -if [ "$#" -ne 1 ] -then - echo "Usage: $0 " - exit 1 -fi - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -VERSION="$1" -MINOR="$( echo ${VERSION} | cut -d\. -f1-2 )" - -VERSION_MATCHER="([a-z0-9\\.-]+)" -PROST_CRATE_MATCHER="(prost|prost-[a-z]+)" - -# Update the README.md. -sed -i -E "s/${PROST_CRATE_MATCHER} = \"${VERSION_MATCHER}\"/\1 = \"${MINOR}\"/" "$DIR/README.md" - -# Update html_root_url attributes. -sed -i -E "s~html_root_url = \"https://docs\.rs/${PROST_CRATE_MATCHER}/$VERSION_MATCHER\"~html_root_url = \"https://docs.rs/\1/${VERSION}\"~" \ - "$DIR/src/lib.rs" \ - "$DIR/prost-derive/src/lib.rs" \ - "$DIR/prost-build/src/lib.rs" \ - "$DIR/prost-types/src/lib.rs" - -# Update Cargo.toml version fields. -sed -i -E "s/^version = \"${VERSION_MATCHER}\"$/version = \"${VERSION}\"/" \ - "$DIR/Cargo.toml" \ - "$DIR/prost-derive/Cargo.toml" \ - "$DIR/prost-build/Cargo.toml" \ - "$DIR/prost-types/Cargo.toml" - -# Update Cargo.toml dependency versions. -sed -i -E "s/^${PROST_CRATE_MATCHER} = \{ version = \"${VERSION_MATCHER}\"/\1 = { version = \"${VERSION}\"/" \ - "$DIR/Cargo.toml" \ - "$DIR/prost-derive/Cargo.toml" \ - "$DIR/prost-build/Cargo.toml" \ - "$DIR/prost-types/Cargo.toml" - -git commit -a -m "release ${VERSION}" -git tag -a "v${VERSION}" -m "release ${VERSION}" diff --git a/src/rust/vendor/prost/publish-release.sh b/src/rust/vendor/prost/publish-release.sh deleted file mode 100755 index 9b014af3a5..0000000000 --- a/src/rust/vendor/prost/publish-release.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# Script which automates publishing a crates.io release of the prost crates. - -set -ex - -if [ "$#" -ne 0 ] -then - echo "Usage: $0" - exit 1 -fi - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -CRATES=( \ - "prost-derive" \ - "." \ - "prost-types" \ - "prost-build" \ -) - -for CRATE in "${CRATES[@]}"; do - pushd "$DIR/$CRATE" - - echo "Publishing $CRATE" - - cargo publish - - echo "Sleeping 5 seconds...for the release to be visible" - sleep 5 - - popd -done diff --git a/src/rust/vendor/prost/src/encoding.rs b/src/rust/vendor/prost/src/encoding.rs index e4d2aa274a..88f65e6438 100644 --- a/src/rust/vendor/prost/src/encoding.rs +++ b/src/rust/vendor/prost/src/encoding.rs @@ -9,7 +9,6 @@ use alloc::format; use alloc::string::String; use alloc::vec::Vec; use core::cmp::min; -use core::convert::TryFrom; use core::mem; use core::str; use core::u32; @@ -23,11 +22,9 @@ use crate::Message; /// Encodes an integer value into LEB128 variable length format, and writes it to the buffer. /// The buffer must have enough remaining space (maximum 10 bytes). #[inline] -pub fn encode_varint(mut value: u64, buf: &mut B) -where - B: BufMut, -{ - loop { +pub fn encode_varint(mut value: u64, buf: &mut impl BufMut) { + // Varints are never more than 10 bytes + for _ in 0..10 { if value < 0x80 { buf.put_u8(value as u8); break; @@ -40,10 +37,7 @@ where /// Decodes a LEB128-encoded variable length integer from the buffer. #[inline] -pub fn decode_varint(buf: &mut B) -> Result -where - B: Buf, -{ +pub fn decode_varint(buf: &mut impl Buf) -> Result { let bytes = buf.chunk(); let len = bytes.len(); if len == 0 { @@ -163,10 +157,7 @@ fn decode_varint_slice(bytes: &[u8]) -> Result<(u64, usize), DecodeError> { /// [1]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/encoding/protowire/wire.go#L358 #[inline(never)] #[cold] -fn decode_varint_slow(buf: &mut B) -> Result -where - B: Buf, -{ +fn decode_varint_slow(buf: &mut impl Buf) -> Result { let mut value = 0; for count in 0..min(10, buf.remaining()) { let byte = buf.get_u8(); @@ -301,10 +292,7 @@ impl TryFrom for WireType { /// Encodes a Protobuf field key, which consists of a wire type designator and /// the field tag. #[inline] -pub fn encode_key(tag: u32, wire_type: WireType, buf: &mut B) -where - B: BufMut, -{ +pub fn encode_key(tag: u32, wire_type: WireType, buf: &mut impl BufMut) { debug_assert!((MIN_TAG..=MAX_TAG).contains(&tag)); let key = (tag << 3) | wire_type as u32; encode_varint(u64::from(key), buf); @@ -313,10 +301,7 @@ where /// Decodes a Protobuf field key, which consists of a wire type designator and /// the field tag. #[inline(always)] -pub fn decode_key(buf: &mut B) -> Result<(u32, WireType), DecodeError> -where - B: Buf, -{ +pub fn decode_key(buf: &mut impl Buf) -> Result<(u32, WireType), DecodeError> { let key = decode_varint(buf)?; if key > u64::from(u32::MAX) { return Err(DecodeError::new(format!("invalid key value: {}", key))); @@ -380,15 +365,12 @@ where Ok(()) } -pub fn skip_field( +pub fn skip_field( wire_type: WireType, tag: u32, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, -) -> Result<(), DecodeError> -where - B: Buf, -{ +) -> Result<(), DecodeError> { ctx.limit_reached()?; let len = match wire_type { WireType::Varint => decode_varint(buf).map(|_| 0)?, @@ -421,10 +403,7 @@ where /// Helper macro which emits an `encode_repeated` function for the type. macro_rules! encode_repeated { ($ty:ty) => { - pub fn encode_repeated(tag: u32, values: &[$ty], buf: &mut B) - where - B: BufMut, - { + pub fn encode_repeated(tag: u32, values: &[$ty], buf: &mut impl BufMut) { for value in values { encode(tag, value, buf); } @@ -438,15 +417,12 @@ macro_rules! merge_repeated_numeric { $wire_type:expr, $merge:ident, $merge_repeated:ident) => { - pub fn $merge_repeated( + pub fn $merge_repeated( wire_type: WireType, values: &mut Vec<$ty>, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if wire_type == WireType::LengthDelimited { // Packed. merge_loop(values, buf, ctx, |values, buf, ctx| { @@ -486,12 +462,12 @@ macro_rules! varint { pub mod $proto_ty { use crate::encoding::*; - pub fn encode(tag: u32, $to_uint64_value: &$ty, buf: &mut B) where B: BufMut { + pub fn encode(tag: u32, $to_uint64_value: &$ty, buf: &mut impl BufMut) { encode_key(tag, WireType::Varint, buf); encode_varint($to_uint64, buf); } - pub fn merge(wire_type: WireType, value: &mut $ty, buf: &mut B, _ctx: DecodeContext) -> Result<(), DecodeError> where B: Buf { + pub fn merge(wire_type: WireType, value: &mut $ty, buf: &mut impl Buf, _ctx: DecodeContext) -> Result<(), DecodeError> { check_wire_type(WireType::Varint, wire_type)?; let $from_uint64_value = decode_varint(buf)?; *value = $from_uint64; @@ -500,7 +476,7 @@ macro_rules! varint { encode_repeated!($ty); - pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut B) where B: BufMut { + pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut impl BufMut) { if values.is_empty() { return; } encode_key(tag, WireType::LengthDelimited, buf); @@ -609,23 +585,17 @@ macro_rules! fixed_width { pub mod $proto_ty { use crate::encoding::*; - pub fn encode(tag: u32, value: &$ty, buf: &mut B) - where - B: BufMut, - { + pub fn encode(tag: u32, value: &$ty, buf: &mut impl BufMut) { encode_key(tag, $wire_type, buf); buf.$put(*value); } - pub fn merge( + pub fn merge( wire_type: WireType, value: &mut $ty, - buf: &mut B, + buf: &mut impl Buf, _ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { check_wire_type($wire_type, wire_type)?; if buf.remaining() < $width { return Err(DecodeError::new("buffer underflow")); @@ -636,10 +606,7 @@ macro_rules! fixed_width { encode_repeated!($ty); - pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut B) - where - B: BufMut, - { + pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut impl BufMut) { if values.is_empty() { return; } @@ -759,15 +726,12 @@ macro_rules! length_delimited { ($ty:ty) => { encode_repeated!($ty); - pub fn merge_repeated( + pub fn merge_repeated( wire_type: WireType, values: &mut Vec<$ty>, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { check_wire_type(WireType::LengthDelimited, wire_type)?; let mut value = Default::default(); merge(wire_type, &mut value, buf, ctx)?; @@ -794,23 +758,18 @@ macro_rules! length_delimited { pub mod string { use super::*; - pub fn encode(tag: u32, value: &String, buf: &mut B) - where - B: BufMut, - { + pub fn encode(tag: u32, value: &String, buf: &mut impl BufMut) { encode_key(tag, WireType::LengthDelimited, buf); encode_varint(value.len() as u64, buf); buf.put_slice(value.as_bytes()); } - pub fn merge( + + pub fn merge( wire_type: WireType, value: &mut String, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { // ## Unsafety // // `string::merge` reuses `bytes::merge`, with an additional check of utf-8 @@ -882,14 +841,10 @@ mod sealed { fn len(&self) -> usize; /// Replace contents of this buffer with the contents of another buffer. - fn replace_with(&mut self, buf: B) - where - B: Buf; + fn replace_with(&mut self, buf: impl Buf); /// Appends this buffer to the (contents of) other buffer. - fn append_to(&self, buf: &mut B) - where - B: BufMut; + fn append_to(&self, buf: &mut impl BufMut); fn is_empty(&self) -> bool { self.len() == 0 @@ -904,17 +859,11 @@ impl sealed::BytesAdapter for Bytes { Buf::remaining(self) } - fn replace_with(&mut self, mut buf: B) - where - B: Buf, - { + fn replace_with(&mut self, mut buf: impl Buf) { *self = buf.copy_to_bytes(buf.remaining()); } - fn append_to(&self, buf: &mut B) - where - B: BufMut, - { + fn append_to(&self, buf: &mut impl BufMut) { buf.put(self.clone()) } } @@ -926,19 +875,13 @@ impl sealed::BytesAdapter for Vec { Vec::len(self) } - fn replace_with(&mut self, buf: B) - where - B: Buf, - { + fn replace_with(&mut self, buf: impl Buf) { self.clear(); self.reserve(buf.remaining()); self.put(buf); } - fn append_to(&self, buf: &mut B) - where - B: BufMut, - { + fn append_to(&self, buf: &mut impl BufMut) { buf.put(self.as_slice()) } } @@ -946,26 +889,18 @@ impl sealed::BytesAdapter for Vec { pub mod bytes { use super::*; - pub fn encode(tag: u32, value: &A, buf: &mut B) - where - A: BytesAdapter, - B: BufMut, - { + pub fn encode(tag: u32, value: &impl BytesAdapter, buf: &mut impl BufMut) { encode_key(tag, WireType::LengthDelimited, buf); encode_varint(value.len() as u64, buf); value.append_to(buf); } - pub fn merge( + pub fn merge( wire_type: WireType, - value: &mut A, - buf: &mut B, + value: &mut impl BytesAdapter, + buf: &mut impl Buf, _ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - A: BytesAdapter, - B: Buf, - { + ) -> Result<(), DecodeError> { check_wire_type(WireType::LengthDelimited, wire_type)?; let len = decode_varint(buf)?; if len > buf.remaining() as u64 { @@ -989,16 +924,12 @@ pub mod bytes { Ok(()) } - pub(super) fn merge_one_copy( + pub(super) fn merge_one_copy( wire_type: WireType, - value: &mut A, - buf: &mut B, + value: &mut impl BytesAdapter, + buf: &mut impl Buf, _ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - A: BytesAdapter, - B: Buf, - { + ) -> Result<(), DecodeError> { check_wire_type(WireType::LengthDelimited, wire_type)?; let len = decode_varint(buf)?; if len > buf.remaining() as u64 { @@ -1055,10 +986,9 @@ pub mod bytes { pub mod message { use super::*; - pub fn encode(tag: u32, msg: &M, buf: &mut B) + pub fn encode(tag: u32, msg: &M, buf: &mut impl BufMut) where M: Message, - B: BufMut, { encode_key(tag, WireType::LengthDelimited, buf); encode_varint(msg.encoded_len() as u64, buf); @@ -1088,25 +1018,23 @@ pub mod message { ) } - pub fn encode_repeated(tag: u32, messages: &[M], buf: &mut B) + pub fn encode_repeated(tag: u32, messages: &[M], buf: &mut impl BufMut) where M: Message, - B: BufMut, { for msg in messages { encode(tag, msg, buf); } } - pub fn merge_repeated( + pub fn merge_repeated( wire_type: WireType, messages: &mut Vec, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, ) -> Result<(), DecodeError> where M: Message + Default, - B: Buf, { check_wire_type(WireType::LengthDelimited, wire_type)?; let mut msg = M::default(); @@ -1141,26 +1069,24 @@ pub mod message { pub mod group { use super::*; - pub fn encode(tag: u32, msg: &M, buf: &mut B) + pub fn encode(tag: u32, msg: &M, buf: &mut impl BufMut) where M: Message, - B: BufMut, { encode_key(tag, WireType::StartGroup, buf); msg.encode_raw(buf); encode_key(tag, WireType::EndGroup, buf); } - pub fn merge( + pub fn merge( tag: u32, wire_type: WireType, msg: &mut M, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, ) -> Result<(), DecodeError> where M: Message, - B: Buf, { check_wire_type(WireType::StartGroup, wire_type)?; @@ -1178,26 +1104,24 @@ pub mod group { } } - pub fn encode_repeated(tag: u32, messages: &[M], buf: &mut B) + pub fn encode_repeated(tag: u32, messages: &[M], buf: &mut impl BufMut) where M: Message, - B: BufMut, { for msg in messages { encode(tag, msg, buf); } } - pub fn merge_repeated( + pub fn merge_repeated( tag: u32, wire_type: WireType, messages: &mut Vec, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, ) -> Result<(), DecodeError> where M: Message + Default, - B: Buf, { check_wire_type(WireType::StartGroup, wire_type)?; let mut msg = M::default(); @@ -1422,15 +1346,16 @@ pub mod btree_map { #[cfg(test)] mod test { + #[cfg(not(feature = "std"))] use alloc::string::ToString; use core::borrow::Borrow; use core::fmt::Debug; use core::u64; - use ::bytes::{Bytes, BytesMut}; + use ::bytes::BytesMut; use proptest::{prelude::*, test_runner::TestCaseResult}; - use crate::encoding::*; + use super::*; pub fn check_type( value: T, @@ -1602,7 +1527,7 @@ mod test { #[test] fn varint() { - fn check(value: u64, mut encoded: &[u8]) { + fn check(value: u64, encoded: &[u8]) { // Small buffer. let mut buf = Vec::with_capacity(1); encode_varint(value, &mut buf); @@ -1615,11 +1540,14 @@ mod test { assert_eq!(encoded_len_varint(value), encoded.len()); - let roundtrip_value = - decode_varint(&mut <&[u8]>::clone(&encoded)).expect("decoding failed"); + // See: https://github.com/tokio-rs/prost/pull/1008 for copying reasoning. + let mut encoded_copy = encoded; + let roundtrip_value = decode_varint(&mut encoded_copy).expect("decoding failed"); assert_eq!(value, roundtrip_value); - let roundtrip_value = decode_varint_slow(&mut encoded).expect("slow decoding failed"); + let mut encoded_copy = encoded; + let roundtrip_value = + decode_varint_slow(&mut encoded_copy).expect("slow decoding failed"); assert_eq!(value, roundtrip_value); } @@ -1678,14 +1606,18 @@ mod test { ); } + const U64_MAX_PLUS_ONE: &[u8] = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x02]; + #[test] fn varint_overflow() { - let mut u64_max_plus_one: &[u8] = - &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x02]; + let mut copy = U64_MAX_PLUS_ONE; + decode_varint(&mut copy).expect_err("decoding u64::MAX + 1 succeeded"); + } - decode_varint(&mut u64_max_plus_one).expect_err("decoding u64::MAX + 1 succeeded"); - decode_varint_slow(&mut u64_max_plus_one) - .expect_err("slow decoding u64::MAX + 1 succeeded"); + #[test] + fn variant_slow_overflow() { + let mut copy = U64_MAX_PLUS_ONE; + decode_varint_slow(&mut copy).expect_err("slow decoding u64::MAX + 1 succeeded"); } /// This big bowl o' macro soup generates an encoding property test for each combination of map diff --git a/src/rust/vendor/prost/src/error.rs b/src/rust/vendor/prost/src/error.rs index 756ee81729..78874b0388 100644 --- a/src/rust/vendor/prost/src/error.rs +++ b/src/rust/vendor/prost/src/error.rs @@ -1,7 +1,9 @@ //! Protobuf encoding and decoding errors. use alloc::borrow::Cow; +#[cfg(not(feature = "std"))] use alloc::boxed::Box; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::fmt; @@ -129,3 +131,20 @@ impl From for std::io::Error { std::io::Error::new(std::io::ErrorKind::InvalidInput, error) } } + +/// An error indicating that an unknown enumeration value was encountered. +/// +/// The Protobuf spec mandates that enumeration value sets are ‘open’, so this +/// error's value represents an integer value unrecognized by the +/// presently used enum definition. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub struct UnknownEnumValue(pub i32); + +impl fmt::Display for UnknownEnumValue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "unknown enumeration value {}", self.0) + } +} + +#[cfg(feature = "std")] +impl std::error::Error for UnknownEnumValue {} diff --git a/src/rust/vendor/prost/src/lib.rs b/src/rust/vendor/prost/src/lib.rs index 9cc6700870..1c8576a768 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.12.1")] +#![doc(html_root_url = "https://docs.rs/prost/0.13.1")] #![cfg_attr(not(feature = "std"), no_std)] #![doc = include_str!("../README.md")] @@ -17,7 +17,7 @@ mod types; #[doc(hidden)] pub mod encoding; -pub use crate::error::{DecodeError, EncodeError}; +pub use crate::error::{DecodeError, EncodeError, UnknownEnumValue}; pub use crate::message::Message; pub use crate::name::Name; @@ -36,10 +36,7 @@ const RECURSION_LIMIT: u32 = 100; /// /// An error will be returned if the buffer does not have sufficient capacity to encode the /// delimiter. -pub fn encode_length_delimiter(length: usize, buf: &mut B) -> Result<(), EncodeError> -where - B: BufMut, -{ +pub fn encode_length_delimiter(length: usize, buf: &mut impl BufMut) -> Result<(), EncodeError> { let length = length as u64; let required = encoded_len_varint(length); let remaining = buf.remaining_mut(); @@ -69,10 +66,7 @@ pub fn length_delimiter_len(length: usize) -> usize { /// input is required to decode the full delimiter. /// * If the supplied buffer contains more than 10 bytes, then the buffer contains an invalid /// delimiter, and typically the buffer should be considered corrupt. -pub fn decode_length_delimiter(mut buf: B) -> Result -where - B: Buf, -{ +pub fn decode_length_delimiter(mut buf: impl Buf) -> Result { let length = decode_varint(&mut buf)?; if length > usize::max_value() as u64 { return Err(DecodeError::new( @@ -86,10 +80,10 @@ where // Based on serde's equivalent re-export [1], but enabled by default. // // [1]: https://github.com/serde-rs/serde/blob/v1.0.89/serde/src/lib.rs#L245-L256 -#[cfg(feature = "prost-derive")] +#[cfg(feature = "derive")] #[allow(unused_imports)] #[macro_use] extern crate prost_derive; -#[cfg(feature = "prost-derive")] +#[cfg(feature = "derive")] #[doc(hidden)] pub use prost_derive::*; diff --git a/src/rust/vendor/prost/src/message.rs b/src/rust/vendor/prost/src/message.rs index a190f6b47b..a38e9f38f2 100644 --- a/src/rust/vendor/prost/src/message.rs +++ b/src/rust/vendor/prost/src/message.rs @@ -1,8 +1,9 @@ +#[cfg(not(feature = "std"))] use alloc::boxed::Box; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::fmt::Debug; -use core::usize; use bytes::{Buf, BufMut}; @@ -20,24 +21,22 @@ pub trait Message: Debug + Send + Sync { /// /// Meant to be used only by `Message` implementations. #[doc(hidden)] - fn encode_raw(&self, buf: &mut B) + fn encode_raw(&self, buf: &mut impl BufMut) where - B: BufMut, Self: Sized; /// Decodes a field from a buffer, and merges it into `self`. /// /// Meant to be used only by `Message` implementations. #[doc(hidden)] - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, ) -> Result<(), DecodeError> where - B: Buf, Self: Sized; /// Returns the encoded length of the message without a length delimiter. @@ -46,14 +45,13 @@ pub trait Message: Debug + Send + Sync { /// Encodes the message to a buffer. /// /// An error will be returned if the buffer does not have sufficient capacity. - fn encode(&self, buf: &mut B) -> Result<(), EncodeError> + fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> where - B: BufMut, Self: Sized, { let required = self.encoded_len(); let remaining = buf.remaining_mut(); - if required > buf.remaining_mut() { + if required > remaining { return Err(EncodeError::new(required, remaining)); } @@ -75,9 +73,8 @@ pub trait Message: Debug + Send + Sync { /// Encodes the message with a length-delimiter to a buffer. /// /// An error will be returned if the buffer does not have sufficient capacity. - fn encode_length_delimited(&self, buf: &mut B) -> Result<(), EncodeError> + fn encode_length_delimited(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> where - B: BufMut, Self: Sized, { let len = self.encoded_len(); @@ -107,9 +104,8 @@ pub trait Message: Debug + Send + Sync { /// Decodes an instance of the message from a buffer. /// /// The entire buffer will be consumed. - fn decode(mut buf: B) -> Result + fn decode(mut buf: impl Buf) -> Result where - B: Buf, Self: Default, { let mut message = Self::default(); @@ -117,9 +113,8 @@ pub trait Message: Debug + Send + Sync { } /// Decodes a length-delimited instance of the message from the buffer. - fn decode_length_delimited(buf: B) -> Result + fn decode_length_delimited(buf: impl Buf) -> Result where - B: Buf, Self: Default, { let mut message = Self::default(); @@ -130,9 +125,8 @@ pub trait Message: Debug + Send + Sync { /// Decodes an instance of the message from a buffer, and merges it into `self`. /// /// The entire buffer will be consumed. - fn merge(&mut self, mut buf: B) -> Result<(), DecodeError> + fn merge(&mut self, mut buf: impl Buf) -> Result<(), DecodeError> where - B: Buf, Self: Sized, { let ctx = DecodeContext::default(); @@ -145,9 +139,8 @@ pub trait Message: Debug + Send + Sync { /// Decodes a length-delimited instance of the message from buffer, and /// merges it into `self`. - fn merge_length_delimited(&mut self, mut buf: B) -> Result<(), DecodeError> + fn merge_length_delimited(&mut self, mut buf: impl Buf) -> Result<(), DecodeError> where - B: Buf, Self: Sized, { message::merge( @@ -166,22 +159,16 @@ impl Message for Box where M: Message, { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { (**self).encode_raw(buf) } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { (**self).merge_field(tag, wire_type, buf, ctx) } fn encoded_len(&self) -> usize { diff --git a/src/rust/vendor/prost/src/name.rs b/src/rust/vendor/prost/src/name.rs index 1f94de6a72..1b5b4a28ec 100644 --- a/src/rust/vendor/prost/src/name.rs +++ b/src/rust/vendor/prost/src/name.rs @@ -1,27 +1,33 @@ //! Support for associating type name information with a [`Message`]. use crate::Message; + +#[cfg(not(feature = "std"))] 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`. + /// Simple name for this [`Message`]. + /// This name is the same as it appears in the source .proto file, e.g. `FooBar`. 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`. + /// Fully-qualified unique name for this [`Message`]. + /// It's prefixed with the package name and names of any parent messages, + /// e.g. `google.rpc.BadRequest.FieldViolation`. + /// By default, this is the package name followed by the message name. + /// Fully-qualified names must be unique within a domain of Type URLs. fn full_name() -> String { - format!("{}.{}", Self::NAME, Self::PACKAGE) + format!("{}.{}", Self::PACKAGE, Self::NAME) } - /// Type URL for this message, which by default is the full name with a + /// 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`. + /// This can be used when serializing into the `google.protobuf.Any` type. fn type_url() -> String { format!("/{}", Self::full_name()) } diff --git a/src/rust/vendor/prost/src/types.rs b/src/rust/vendor/prost/src/types.rs index 864a2adda1..6e4994bfb3 100644 --- a/src/rust/vendor/prost/src/types.rs +++ b/src/rust/vendor/prost/src/types.rs @@ -5,7 +5,9 @@ //! the `prost-types` crate in order to avoid a cyclic dependency between `prost` and //! `prost-build`. +#[cfg(not(feature = "std"))] use alloc::string::String; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use ::bytes::{Buf, BufMut, Bytes}; @@ -20,24 +22,18 @@ use crate::{ /// `google.protobuf.BoolValue` impl Message for bool { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self { bool::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { bool::merge(wire_type, self, buf, ctx) } else { @@ -58,24 +54,18 @@ impl Message for bool { /// `google.protobuf.UInt32Value` impl Message for u32 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0 { uint32::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { uint32::merge(wire_type, self, buf, ctx) } else { @@ -96,24 +86,18 @@ impl Message for u32 { /// `google.protobuf.UInt64Value` impl Message for u64 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0 { uint64::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { uint64::merge(wire_type, self, buf, ctx) } else { @@ -134,24 +118,18 @@ impl Message for u64 { /// `google.protobuf.Int32Value` impl Message for i32 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0 { int32::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { int32::merge(wire_type, self, buf, ctx) } else { @@ -172,24 +150,18 @@ impl Message for i32 { /// `google.protobuf.Int64Value` impl Message for i64 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0 { int64::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { int64::merge(wire_type, self, buf, ctx) } else { @@ -210,24 +182,18 @@ impl Message for i64 { /// `google.protobuf.FloatValue` impl Message for f32 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0.0 { float::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { float::merge(wire_type, self, buf, ctx) } else { @@ -248,24 +214,18 @@ impl Message for f32 { /// `google.protobuf.DoubleValue` impl Message for f64 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0.0 { double::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { double::merge(wire_type, self, buf, ctx) } else { @@ -286,24 +246,18 @@ impl Message for f64 { /// `google.protobuf.StringValue` impl Message for String { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if !self.is_empty() { string::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { string::merge(wire_type, self, buf, ctx) } else { @@ -324,24 +278,18 @@ impl Message for String { /// `google.protobuf.BytesValue` impl Message for Vec { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if !self.is_empty() { bytes::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { bytes::merge(wire_type, self, buf, ctx) } else { @@ -362,24 +310,18 @@ impl Message for Vec { /// `google.protobuf.BytesValue` impl Message for Bytes { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if !self.is_empty() { bytes::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { bytes::merge(wire_type, self, buf, ctx) } else { @@ -400,21 +342,14 @@ impl Message for Bytes { /// `google.protobuf.Empty` impl Message for () { - fn encode_raw(&self, _buf: &mut B) - where - B: BufMut, - { - } - fn merge_field( + fn encode_raw(&self, _buf: &mut impl BufMut) {} + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { skip_field(wire_type, tag, buf, ctx) } fn encoded_len(&self) -> usize { diff --git a/tools/prost-build-proto/Cargo.lock b/tools/prost-build-proto/Cargo.lock index c7726b075f..4ffe69b3b6 100644 --- a/tools/prost-build-proto/Cargo.lock +++ b/tools/prost-build-proto/Cargo.lock @@ -87,15 +87,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "home" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" -dependencies = [ - "windows-sys", -] - [[package]] name = "indexmap" version = "2.1.0" @@ -182,9 +173,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" +checksum = "e13db3d3fde688c61e2446b4d843bc27a7e8af269a69440c0308021dc92333cc" dependencies = [ "bytes", "prost-derive", @@ -192,9 +183,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.12.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bdf592881d821b83d471f8af290226c8d51402259e9bb5be7f9f8bdebbb11ac" +checksum = "5bb182580f71dd070f88d01ce3de9f4da5021db7115d2e1c3605a754153b77c1" dependencies = [ "bytes", "heck", @@ -209,7 +200,6 @@ dependencies = [ "regex", "syn", "tempfile", - "which", ] [[package]] @@ -221,9 +211,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" +checksum = "18bec9b0adc4eba778b33684b7ba3e7137789434769ee3ce3930463ef904cfca" dependencies = [ "anyhow", "itertools", @@ -234,9 +224,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.12.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e081b29f63d83a4bc75cfc9f3fe424f9156cf92d8a4f0c9407cce9a1b67327cf" +checksum = "cee5168b05f49d4b0ca581206eb14a7b22fafd963efe729ac48eb03266e25cc2" dependencies = [ "prost", ] @@ -331,18 +321,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - [[package]] name = "windows-sys" version = "0.48.0" diff --git a/tools/prost-build-proto/Cargo.toml b/tools/prost-build-proto/Cargo.toml index 6ed0066169..aefd9c7280 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.12.1" +version = "0.13.1"