From dfb480a384be9762ef01487a355a80d9e47e2b55 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 11 Dec 2024 14:43:01 -0500 Subject: [PATCH] Set the factory default value of an attribute This allows to fill specific attributes with the defined default value for the specific object type. If the object does not have a default value for the requested attribute nothing it set on the object. Signed-off-by: Simo Sorce --- src/object.rs | 17 +++++++++++++++++ src/storage/nssdb/mod.rs | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/object.rs b/src/object.rs index 30a4a1d8..8060219c 100644 --- a/src/object.rs +++ b/src/object.rs @@ -502,6 +502,23 @@ pub trait ObjectFactory: Debug + Send + Sync { Ok(obj) } + fn set_attribute_default( + &self, + attr: CK_ATTRIBUTE_TYPE, + obj: &mut Object, + ) -> Result<()> { + let attributes = self.get_attributes(); + match attributes.iter().find(|a| a.get_type() == attr) { + Some(defattr) => { + if defattr.has_default() { + obj.set_attr(defattr.attribute.clone())?; + } + } + None => (), + } + Ok(()) + } + fn default_copy( &self, origin: &Object, diff --git a/src/storage/nssdb/mod.rs b/src/storage/nssdb/mod.rs index 7d5ab1b7..de27508d 100644 --- a/src/storage/nssdb/mod.rs +++ b/src/storage/nssdb/mod.rs @@ -888,8 +888,9 @@ impl Storage for NSSStorage { } /* add back the attributes that we requested, but that do not exist in DB */ for a in NSS_SKIP_ATTRIBUTES { + let factory = facilities.factories.get_object_factory(&obj)?; match attributes.iter().position(|r| r.type_ == a) { - Some(_) => obj.set_attr(Attribute::from_bool(a, true))?, + Some(_) => factory.set_attribute_default(a, &mut obj)?, None => (), } }