Skip to content

Commit

Permalink
docs: reword and annotate a few doccomments
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekMracna authored and dufkan committed Sep 9, 2024
1 parent c56609a commit 343fbbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/protocol/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct Setup {
index: u16,
}

/// Helper intended for use in `iterator.map`
fn index_to_identifier<T>((i, x): (u32, T)) -> (Identifier, T) {
assert!(i > 0);
assert!(i <= u16::MAX as u32);
Expand Down
1 change: 1 addition & 0 deletions src/protocol/gg18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum KeygenRound {
Done(GG18SignContext),
}

/// Collects a hashmap's values sorted by their respective keys
fn map_to_sorted_vec<T>(map: HashMap<u32, T>) -> Vec<T> {
let mut vec: Vec<_> = map.into_iter().collect();
vec.sort_by_key(|(i, _)| *i);
Expand Down
13 changes: 9 additions & 4 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub trait ThresholdProtocol: Protocol {
Self: Sized;
}

/// Deserializes values in a `HashMap`
fn deserialize_map<'de, T: Deserialize<'de>>(
map: &'de HashMap<u32, Vec<u8>>,
) -> serde_json::Result<HashMap<u32, T>> {
Expand All @@ -45,7 +46,7 @@ fn deserialize_map<'de, T: Deserialize<'de>>(
.collect()
}

/// Encode a broadcast message
/// Encode a broadcast message to protobuf format
fn encode_raw_bcast(message: Vec<u8>, protocol_type: ProtocolType) -> Vec<u8> {
ClientMessage {
protocol_type: protocol_type.into(),
Expand All @@ -55,7 +56,7 @@ fn encode_raw_bcast(message: Vec<u8>, protocol_type: ProtocolType) -> Vec<u8> {
.encode_to_vec()
}

/// Serialize and encode a broadcast message
/// Serialize and encode a broadcast message to protobuf format
fn serialize_bcast<T: Serialize>(
value: &T,
protocol_type: ProtocolType,
Expand All @@ -64,7 +65,9 @@ fn serialize_bcast<T: Serialize>(
Ok(encode_raw_bcast(message, protocol_type))
}

/// Encode a Vec of unicast messages
/// Encode unicast messages to protobuf format
///
/// Each message is associated with an index as used by a respective protocol
fn encode_raw_uni(messages: HashMap<u32, Vec<u8>>, protocol_type: ProtocolType) -> Vec<u8> {
ClientMessage {
protocol_type: protocol_type.into(),
Expand All @@ -74,7 +77,9 @@ fn encode_raw_uni(messages: HashMap<u32, Vec<u8>>, protocol_type: ProtocolType)
.encode_to_vec()
}

/// Serialize and encode a map of unicast messages
/// Serialize and encode unicast messages to protobuf format
///
/// Each message is associated with an index as used by a respective protocol
fn serialize_uni<T, I>(kvs: I, protocol_type: ProtocolType) -> serde_json::Result<Vec<u8>>
where
I: IntoIterator<Item = (u32, T)>,
Expand Down

0 comments on commit 343fbbc

Please sign in to comment.