Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 69 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Stellar Development Foundation <info@stellar.org>"]
license = "Apache-2.0"
version = "27.0.0"
edition = "2021"
rust-version = "1.84.0"
rust-version = "1.87.0"

[[bin]]
name = "stellar-xdr"
Expand All @@ -20,7 +20,7 @@ crate-git-revision = "0.0.6"

[dependencies]
cfg_eval = { version = "0.1.2", optional = true }
stellar-strkey = { version = "0.0.13", optional = true }
stellar-strkey = { version = "0.0.18", optional = true }
base64 = { version = "0.22.1", optional = true }
serde = { version = "1.0.139", features = ["derive"], optional = true }
serde_with = { version = "3.12.0", features = ["schemars_0_8"], optional = true }
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#![allow(clippy::tabs_in_doc_comments)]
#![allow(clippy::doc_markdown)]
#![allow(clippy::doc_lazy_continuation)]
#![allow(clippy::unnecessary_semicolon)]
#![allow(clippy::non_std_lazy_statics)]
#![allow(unused_attributes)]
Comment on lines +9 to 11

//! Library and CLI containing types and functionality for working with Stellar
Expand Down
36 changes: 14 additions & 22 deletions src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ impl core::str::FromStr for MuxedAccount {
ed25519: Uint256(ed25519),
id,
})),
stellar_strkey::Strkey::PrivateKeyEd25519(_)
| stellar_strkey::Strkey::PreAuthTx(_)
stellar_strkey::Strkey::PreAuthTx(_)
| stellar_strkey::Strkey::HashX(_)
| stellar_strkey::Strkey::SignedPayloadEd25519(_)
| stellar_strkey::Strkey::Contract(_)
Expand Down Expand Up @@ -204,10 +203,8 @@ impl core::fmt::Display for SignerKeyEd25519SignedPayload {
ed25519: Uint256(ed25519),
payload,
} = self;
let k = stellar_strkey::ed25519::SignedPayload {
ed25519: *ed25519,
payload: payload.into(),
};
let k = stellar_strkey::ed25519::SignedPayload::new(*ed25519, payload.as_ref())
.map_err(|_| core::fmt::Error)?;
Comment on lines +206 to +207

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle empty signed-payloads without panicking

When a SignerKeyEd25519SignedPayload is decoded or constructed with an empty payload (the generated field is BytesM<64>, which has no non-empty invariant), this new call to stellar_strkey::ed25519::SignedPayload::new returns InvalidPayloadLength. Mapping that to fmt::Error makes Display fail, so callers using .to_string() panic and serde SerializeDisplay can no longer serialize a value that the XDR reader accepts. Either preserve the old encoding path for empty payloads or reject that value before it can be represented as this XDR type.

Useful? React with 👍 / 👎.

let s = k.to_string();
f.write_str(&s)?;
Ok(())
Expand All @@ -217,11 +214,10 @@ impl core::fmt::Display for SignerKeyEd25519SignedPayload {
impl core::str::FromStr for SignerKeyEd25519SignedPayload {
type Err = Error;
fn from_str(s: &str) -> core::result::Result<Self, Self::Err> {
let stellar_strkey::ed25519::SignedPayload { ed25519, payload } =
stellar_strkey::ed25519::SignedPayload::from_str(s)?;
let sp = stellar_strkey::ed25519::SignedPayload::from_str(s)?;
Ok(SignerKeyEd25519SignedPayload {
ed25519: Uint256(ed25519),
payload: payload.try_into()?,
ed25519: Uint256(*sp.ed25519()),
payload: sp.payload().try_into()?,
})
}
}
Expand All @@ -240,16 +236,13 @@ impl core::str::FromStr for SignerKey {
stellar_strkey::Strkey::HashX(stellar_strkey::HashX(h)) => {
Ok(SignerKey::HashX(Uint256(h)))
}
stellar_strkey::Strkey::SignedPayloadEd25519(
stellar_strkey::ed25519::SignedPayload { ed25519, payload },
) => Ok(SignerKey::Ed25519SignedPayload(
SignerKeyEd25519SignedPayload {
ed25519: Uint256(ed25519),
payload: payload.try_into()?,
},
)),
stellar_strkey::Strkey::PrivateKeyEd25519(_)
| stellar_strkey::Strkey::Contract(_)
stellar_strkey::Strkey::SignedPayloadEd25519(sp) => Ok(
SignerKey::Ed25519SignedPayload(SignerKeyEd25519SignedPayload {
ed25519: Uint256(*sp.ed25519()),
payload: sp.payload().try_into()?,
}),
),
stellar_strkey::Strkey::Contract(_)
| stellar_strkey::Strkey::MuxedAccountEd25519(_)
| stellar_strkey::Strkey::LiquidityPool(_)
| stellar_strkey::Strkey::ClaimableBalance(_) => Err(Error::Invalid),
Expand Down Expand Up @@ -332,8 +325,7 @@ impl core::str::FromStr for ScAddress {
)) => Ok(ScAddress::ClaimableBalance(
ClaimableBalanceId::ClaimableBalanceIdTypeV0(Hash(claimable_balance)),
)),
stellar_strkey::Strkey::PrivateKeyEd25519(_)
| stellar_strkey::Strkey::PreAuthTx(_)
stellar_strkey::Strkey::PreAuthTx(_)
| stellar_strkey::Strkey::HashX(_)
| stellar_strkey::Strkey::SignedPayloadEd25519(_) => Err(Error::Invalid),
}
Expand Down
Loading