Skip to content

Commit

Permalink
validate data CID is present on write
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Apr 30, 2024
1 parent bbffb56 commit 2c34aaa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/dwn/src/actor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<D: DataStore, M: MessageStore> Actor<D, M> {
}
}

// Pull from remotes.
// Pull all local records from remotes.
let mut record_ids = HashSet::new();

for message in self
Expand Down
23 changes: 16 additions & 7 deletions crates/dwn/src/handlers/records/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ pub async fn handle_records_write(
}
};

// Validate data format is present.
if message.data.is_some() && descriptor.data_format.is_none() {
return Err(HandleMessageError::InvalidDescriptor(
"Data format missing".to_string(),
));
}

// Validate data CID is present.
// We do not validate the CID, because we may want to store a record
// without storing its associated data.
if message.data.is_some() && descriptor.data_cid.is_none() {
return Err(HandleMessageError::InvalidDescriptor(
"Data CID missing".to_string(),
));
}

// Get messages for the record.
let messages = message_store
.query_records(
Expand Down Expand Up @@ -87,13 +103,6 @@ pub async fn handle_records_write(
}
}

// Validate data format is present.
if message.data.is_some() && descriptor.data_format.is_none() {
return Err(HandleMessageError::InvalidDescriptor(
"Data format missing".to_string(),
));
}

// Validate data matches schema.
if let Some(schema_url) = &descriptor.schema {
if let Some(Data::Base64(data)) = &message.data {
Expand Down

0 comments on commit 2c34aaa

Please sign in to comment.