diff --git a/src/object.rs b/src/object.rs index 30a4a1d..8060219 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 7d5ab1b..de27508 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 => (), } }