Skip to content

Commit

Permalink
Set the factory default value of an attribute
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
simo5 committed Dec 11, 2024
1 parent 202a2cb commit dfb480a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/storage/nssdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => (),
}
}
Expand Down

0 comments on commit dfb480a

Please sign in to comment.