-
Notifications
You must be signed in to change notification settings - Fork 61
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
Expose more fine-grained control over find_objects
#106
Comments
One downside to the API above the mutable borrow means it is not possible to interleave calls to Also, I just realized that it would be necessary to change |
Another downside is that we can't handle errors from I would consider this much less ergonomic than the API above. I doubt anyone cares much about handling errors from |
The use-case is good and I like your ideas. 👍 While looking at your proposed API it makes a striking resemblance to the Iterator API. Just wondering, have you considered providing an interface like this? Of course then you'd have to return PRs of course welcome! Sorry in advance for the delay in reviewing 🙇 |
On Thu, 2022-11-24 at 01:14 -0800, Wiktor Kwapisiewicz wrote:
While looking at your proposed API it makes a striking resemblance to
the Iterator API. Just wondering, have you considered providing an
interface like this? Of course then you'd have to return
Option<Result<ObjectHandle>> (just like fallible iterators) and
probably do some caching (so that FindObjects is not too frequently
called).
I considered something like that. For the sake of simplicity, I only
wanted to introduce one API at a time. I'm pretty sure an iterator-
like API could be built on top of this one, but not the other way
around. As you said, you'd have to make decisions about caching and
error handling. I'd like to do the minimum possible to build a safe
but flexible API first.
…--
James Hagborg
|
I guess this issue can be closed now? |
Yes, thanks a lot for your work @keldonin! @jhagborgftx, if you don't find what you want in what #223 brought, feel free to re-open 😸 |
Currently, the only way to search for objects is through
Session::find_objects
, which returns a vector of all objects. If there may be a huge number of objects, it's desirable to be able to find only a bounded number of objects. This is possible with PKCS#11, but the functionality is not exposed by this crate.Further, it may be desirable to iterate through objects incrementally, i.e. calling
C_FindObjects
multiple times, with some processing in between each call. Also, the user may care whether the library makes several small calls toC_FindObjects
, or one large one, especially if the HSM is being accessed over a network.I believe all of these needs may be met safely by the following API:
Although
find_next
could return justResult<Vec<ObjectHandle>>
, I think returning anOption
is more ergonomic, sinceNone
when finishedwhile let
notationI believe the current implementation of
Session::find_objects
, as well as any other versions we might want to make (e.g.Session::find_objects_bounded(template, object_count)
), can be implemented in terms of this one.I will make a PR with something like this soon, but first I would like to collect some feedback about the API.
The text was updated successfully, but these errors were encountered: