Skip to content

Fix AllowedMechanisms issue - #368

Open
ionut-arm wants to merge 1 commit into
mainfrom
main-allowedmech-fix
Open

ionut-arm wants to merge 1 commit into
mainfrom
main-allowedmech-fix

Conversation

@ionut-arm

Copy link
Copy Markdown
Member

No description provided.

Signed-off-by: Ionut Mihalcea <ionut.mihalcea@arm.com>
Comment on lines +16 to +20
assert_eq!(raw.type_, CKA_ALLOWED_MECHANISMS);
assert_eq!(
raw.ulValueLen as usize,
mechanisms.len() * size_of::<CK_MECHANISM_TYPE>()
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Gemini suggests to copy the packed member before comparing to avoid accessing unaligned struct members of packed structure:

    let raw_type = raw.type_;
    let raw_len = raw.ulValueLen;

    // Assert against the local, properly aligned variables
    assert_eq!(raw_type, CKA_ALLOWED_MECHANISMS);
    assert_eq!(
        raw_len as usize,
        mechanisms.len() * size_of::<CK_MECHANISM_TYPE>()
    );

or you can force a copy by wrapping the field accesses in a block expression:

assert_eq!({ raw.type_ }, CKA_ALLOWED_MECHANISMS);

Otherwise looks good!

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