Skip to content

Commit aee7741

Browse files
committed
Return empty result on unknown object class
Update `prepare_search` to return `Ok(None)` instead of `Err(CKR_ATTRIBUTE_VALUE_INVALID)` when an unknown or unsupported `CKA_CLASS` is encountered. This ensures that searches for unsupported object types simply return an empty result set rather than failing with an error. Signed-off-by: Simo Sorce <simo@redhat.com>
1 parent 6395597 commit aee7741

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/storage/nssdb/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,9 @@ impl NSSStorage {
660660
* certs or keys databases or both need to be searched.
661661
*/
662662
/// Prepares search statements
663-
fn prepare_search(template: &[CK_ATTRIBUTE]) -> Result<NSSSearchQuery> {
663+
fn prepare_search(
664+
template: &[CK_ATTRIBUTE],
665+
) -> Result<Option<NSSSearchQuery>> {
664666
let mut do_private = true;
665667
let mut do_public = true;
666668
let mut query = NSSSearchQuery {
@@ -678,7 +680,7 @@ impl NSSStorage {
678680
CKO_PRIVATE_KEY | CKO_SECRET_KEY => do_public = false,
679681
CKO_PUBLIC_KEY | CKO_CERTIFICATE | CKO_TRUST
680682
| CKO_NSS_TRUST => do_private = false,
681-
_ => return Err(CKR_ATTRIBUTE_VALUE_INVALID)?,
683+
_ => return Ok(None),
682684
}
683685
}
684686
}
@@ -738,7 +740,7 @@ impl NSSStorage {
738740
});
739741
}
740742
}
741-
Ok(query)
743+
Ok(Some(query))
742744
}
743745

744746
/// Executes a prepared search query against a specific table (public or
@@ -767,7 +769,10 @@ impl NSSStorage {
767769
template: &[CK_ATTRIBUTE],
768770
) -> Result<Vec<String>> {
769771
let mut result = Vec::<String>::new();
770-
let query = Self::prepare_search(template)?;
772+
let query = match Self::prepare_search(template)? {
773+
Some(q) => q,
774+
None => return Ok(result),
775+
};
771776
let mut conn = self.conn.lock()?;
772777
if let Some(ref sql) = query.public {
773778
let mut public = Self::search_with_params(

0 commit comments

Comments
 (0)