Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Encode/Decode for Box<T> #37

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

kostko
Copy link
Member

@kostko kostko commented Aug 27, 2024

No description provided.

@kostko kostko requested a review from peternose August 27, 2024 10:42
@kostko kostko self-assigned this Aug 27, 2024
Copy link
Contributor

@peternose peternose left a comment

Choose a reason for hiding this comment

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

Looks good.

Be aware that in one of the previous commits we fixed encoding of omitempty structs with empty omitempty fields. This could cause problems with backwards compatibility as some old signatures might become invalid. For example, cbor 0.5.2 encodes OuterStruct to the same bytes as EmptyStruct if OuterStruct.A.B == 0. Before, it encoded the same way as OuterStruct2.

I doubt that we ever signed such structs, as is totally unsafe as two structs with different meaning could have the same encoding and a signature for one would be valid for both structs. For example, OuterStruct encodes to the same value as MyStruct and EmptyStruct if OuterStruct.A.B == 0 and MyStruct.C == 0. Therefore, if one signs OuterStruct he also signs the other two. Which could be dangerous if one struct is used for transfering funds.

Using Go instead of Rust for clarity :)

type OuterStruct struct {
	A InnerStruct `json:"a,omitempty"`
}

type InnerStruct struct {
	B uint `json:"b,omitempty"`
}

type EmptyStruct struct {
}

type MyStruct struct {
	C uint `json:"c,omitempty"`
}

type OuterStruct2 struct {
	A InnerStruct `json:"a"`
}

Once we are sure that this is not a problem, the following PR can be merged:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants