mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-24 15:28:10 +00:00
stellar: fix ManageDataOp value padding
This commit is contained in:
parent
97a5fd14b6
commit
3c62db2696
@ -56,8 +56,7 @@ def write_manage_data_op(w, msg: StellarManageDataOp):
|
||||
writers.write_string(w, msg.key)
|
||||
writers.write_bool(w, bool(msg.value))
|
||||
if msg.value:
|
||||
writers.write_uint32(w, len(msg.value))
|
||||
writers.write_bytes(w, msg.value)
|
||||
writers.write_string(w, msg.value)
|
||||
|
||||
|
||||
def write_manage_offer_op(w, msg: StellarManageOfferOp):
|
||||
|
@ -5,9 +5,16 @@ from apps.common.writers import write_bytes, write_uint32_be, write_uint64_be
|
||||
write_uint32 = write_uint32_be
|
||||
write_uint64 = write_uint64_be
|
||||
|
||||
if False:
|
||||
from typing import AnyStr
|
||||
|
||||
def write_string(w, s: str):
|
||||
buf = s.encode()
|
||||
|
||||
def write_string(w, s: AnyStr) -> None:
|
||||
"""Write XDR string padded to a multiple of 4 bytes."""
|
||||
if isinstance(s, str):
|
||||
buf = s.encode()
|
||||
else:
|
||||
buf = s
|
||||
write_uint32(w, len(buf))
|
||||
write_bytes(w, buf)
|
||||
# if len isn't a multiple of 4, add padding bytes
|
||||
|
@ -1088,9 +1088,7 @@ bool stellar_confirmManageDataOp(const StellarManageDataOp *msg) {
|
||||
// value
|
||||
if (msg->has_value) {
|
||||
stellar_hashupdate_bool(true);
|
||||
// Variable opaque field is length + raw bytes
|
||||
stellar_hashupdate_uint32(msg->value.size);
|
||||
stellar_hashupdate_bytes(msg->value.bytes, msg->value.size);
|
||||
stellar_hashupdate_string(msg->value.bytes, msg->value.size);
|
||||
} else {
|
||||
stellar_hashupdate_bool(false);
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ from trezorlib.tools import parse_path
|
||||
|
||||
from ..common import MNEMONIC12
|
||||
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.altcoin,
|
||||
pytest.mark.stellar,
|
||||
@ -66,7 +65,7 @@ ADDRESS_N = parse_path(stellar.DEFAULT_BIP32_PATH)
|
||||
NETWORK_PASSPHRASE = "Test SDF Network ; September 2015"
|
||||
|
||||
|
||||
def _create_msg(self) -> messages.StellarSignTx:
|
||||
def _create_msg() -> messages.StellarSignTx:
|
||||
return messages.StellarSignTx(
|
||||
source_account="GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW",
|
||||
fee=100,
|
||||
@ -260,3 +259,16 @@ def test_sign_tx_set_options(client):
|
||||
b64encode(response.signature)
|
||||
== b"22rfcOrxBiE5akpNsnWX8yPgAOpclbajVqXUaXMNeL000p1OhFhi050t1+GNRpoSNyfVsJGNvtlICGpH4ksDAQ=="
|
||||
)
|
||||
|
||||
|
||||
def test_manage_data(client):
|
||||
tx = _create_msg()
|
||||
|
||||
# testing a value whose length is not divisible by 4
|
||||
op = messages.StellarManageDataOp(key="data", value=b"abc")
|
||||
|
||||
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
|
||||
assert (
|
||||
b64encode(response.signature)
|
||||
== b"MTa8fmhM7BxYYo9kY1RKQFFrg/MVfzsgiPSuP7+SJZjhQ3P1ucN5JUnfmD5484ULRPjVTd+0YYjS6hScLupbCQ=="
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user