@@ -15,6 +15,41 @@ const MAX_OBJECT_COUNT: usize = 10;
1515
1616impl Session {
1717 /// Search for session objects matching a template
18+ ///
19+ /// # Arguments
20+ /// * `template` - A [Attribute] of search parameters that will be used
21+ /// to find objects.
22+ ///
23+ /// # Examples
24+ ///
25+ /// ```rust
26+ /// # fn main() -> testresult::TestResult {
27+ /// # use cryptoki::session::Session;
28+ /// # use cryptoki::context::Pkcs11;
29+ /// # use cryptoki::object::{Attribute, AttributeType, CertificateType, ObjectClass, ObjectHandle};
30+ /// #
31+ /// # let mut client = Pkcs11::new(
32+ /// # std::env::var("PKCS11_SOFTHSM2_MODULE")
33+ /// # .unwrap_or_else(|_| "/usr/local/lib/softhsm/libsofthsm2.so".to_string()),
34+ /// # )?;
35+ /// # client.initialize(cryptoki::context::CInitializeArgs::OsThreads)?;
36+ /// #
37+ /// # // Use the first slot
38+ /// # let slot = client.get_all_slots()?[0];
39+ /// # let session = client.open_ro_session(slot)?;
40+ /// #
41+ /// // Get handles to all of the x509 certificates on the card
42+ /// let search = vec![Attribute::Class(ObjectClass::CERTIFICATE), Attribute::CertificateType(CertificateType::X_509)];
43+ /// for handle in session.find_objects(&search)? {
44+ /// // each cert: get the "value" which will be the raw certificate data
45+ /// for value in session.get_attributes(handle, &[AttributeType::Value])? {
46+ /// if let Attribute::Value(value) = value {
47+ /// println!("Certificate value: {value:?}");
48+ /// }
49+ /// }
50+ /// }
51+ /// # Ok(()) }
52+ /// ```
1853 pub fn find_objects ( & self , template : & [ Attribute ] ) -> Result < Vec < ObjectHandle > > {
1954 let mut template: Vec < CK_ATTRIBUTE > = template. iter ( ) . map ( |attr| attr. into ( ) ) . collect ( ) ;
2055
0 commit comments