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

Handle the priority field correctly when a value is explicitly set #9

Merged
merged 1 commit into from
Nov 8, 2022

Conversation

msiegen
Copy link
Contributor

@msiegen msiegen commented Nov 6, 2022

I encountered the error
json: cannot unmarshal number into Go struct field keyslot.keyslots.priority of type string
when trying to unlock a volume that had had one of its keyslots boosted in priority with
cryptsetup config --priority prefer --key-slot 1 /dev/sda3.

This commit resolves it by using a pointer field to expose presence information.

Copy link
Owner

@anatol anatol left a comment

Choose a reason for hiding this comment

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

Otherwise, the change looks good.

Thank you

json_metadata.go Show resolved Hide resolved
highPrio = append(highPrio, i)
} else {
} else if k.Priority == nil || *k.Priority == 1 {
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please add a testcase for this bug to luks2_test.go? It should be a one-liner something like

func TestLuks2PreferedPriority(t *testing.T) {
	runLuks2Test(t, 0, "--priority", "prefer")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. It turns out luksFormat doesn't interpret the the --priority flag, but I added a test that runs an additional config command.

This resolves an error:
json: cannot unmarshal number into Go struct field keyslot.keyslots.priority of type string
Copy link
Contributor Author

@msiegen msiegen left a comment

Choose a reason for hiding this comment

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

Made the changes. I'm new to Git, so I hope the squash operation worked correctly.

@anatol anatol merged commit 607b42b into anatol:master Nov 8, 2022
@anatol
Copy link
Owner

anatol commented Nov 8, 2022

Looks good. Thank you for this contribution.

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