Skip to content

Accept TryFrom<CK_MECHANISM_TYPE> for vendor mechanisms#364

Merged
wiktor-k merged 1 commit into
parallaxsecond:mainfrom
jwnrt:tryfrom-vendor-mechanism
Jun 11, 2026
Merged

Accept TryFrom<CK_MECHANISM_TYPE> for vendor mechanisms#364
wiktor-k merged 1 commit into
parallaxsecond:mainfrom
jwnrt:tryfrom-vendor-mechanism

Conversation

@jwnrt

@jwnrt jwnrt commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Hi, we've been using a similar patch downstream in OpenTitan so I wanted to upstream this change.

Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
@hug-dev

hug-dev commented Jun 3, 2026

Copy link
Copy Markdown
Member

Hello!

Thanks for the patch! We currently have new_vendor_defined to create vendor defined mechanism types. Could that be used in your use case?

@jwnrt

jwnrt commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Yes, you're right, we can have this conditional on our side and call new_vendor_defined.

This patch would mostly be ergonomics and would allow dependents to avoid taking a dependency on cryptoki-sys (in order to access CKM_VENDOR_DEFINED). It won't block us if you don't accept the patch :-)

@hug-dev

hug-dev commented Jun 4, 2026

Copy link
Copy Markdown
Member

I see! I was afraid this would silently allow a lot of mechanisms as vendor defined compared with the function call which is a bit more explicit. But I guess this is mostly ergonomics and allowed by the standard so fine with me!

Note that I don't think you always need to import CKM_VENDOR_DEFINED if you already know the CKM value of your vendor mechanisms:

fn main() {
    let toto = cryptoki::mechanism::MechanismType::new_vendor_defined(0x80000406).unwrap();
    println!("Hello, world {} !", toto);
}

@hug-dev hug-dev requested review from Jakuje and wiktor-k June 5, 2026 07:59
@Jakuje

Jakuje commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Any chance to create some simple test case with vendor specific mechanism? Do we know about some implemented in the existing software tokens? Or should we just make some sanity test with examples how these should be handled? I find this area still quite under-documented and untested.

@hug-dev

hug-dev commented Jun 11, 2026

Copy link
Copy Markdown
Member

Agree about adding tests but I think this could also be done in another PR, since the we already allow this functionality via other methods!

@wiktor-k wiktor-k left a comment

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.

Agree about adding tests but I think this could also be done in another PR, since the we already allow this functionality via other methods!

Thinking about this, yeah, we have a bad habit of withholding many good contributions over tiny things by accident 😅

I agree that we can merge this as is.

@wiktor-k wiktor-k merged commit 6cc2278 into parallaxsecond:main Jun 11, 2026
44 checks passed
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.

4 participants