Adding WrapKey to p11/session
Initial stab at https://github.com/miekg/pkcs11/issues/94
This is a drive-by, so feel free to disregard.
Wouldn't this be a nicer API if implemented in terms of p11.PrivateKey and p11.PublicKey? I.e.,
func (priv PrivateKey) Wrap(mechanism pkcs11.Mechanism, wrapper PublicKey) {
s := priv.session
s.Lock()
defer s.Unlock()
return s.ctx.WrapKey(s.handle,
[]*pkcs11.Mechanism{&mechanism},
wrapper.objectHandle,
priv.objectHandle)
}
Admittedly, this only addresses the use-case of wrapping a private key using a public key. I was going to open a separate PR to add a SecretKey type to complement to existing PrivateKey and PublicKey in p11 (i.e., an object with class pkcs11.CKA_SECRET_KEY). That SecretKey could have its own implementation of ~WrapKey~ Wrap(), but also accepting a PublicKey as the arg.
That idea also only addresses the use-case of wrapping with a PublicKey, which may be too limited, but I personally would prefer a more 'narrow' API in the p11 package than handling raw pkcs11.ObjectHandles (or p11.Objects), which could be easily mis-used.
What do you think?
I agree with @emmanuel
Sounds good!