Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions context/interfaces/src/ident.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

## Public interface
```rust
/// Human-readable mesh name.
pub struct Name(pub Vec<String>);
/// Human-readable mesh name. The label representation is private; construct
/// via `FromStr` so the non-empty invariant always holds.
pub struct Name;

/// Name or wildcard authority pattern over mesh names.
pub struct NamePattern;
Expand Down
4 changes: 2 additions & 2 deletions src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const MAX_LABEL_LENGTH: usize = 63;
#[derive(
Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, SerializeDisplay, DeserializeFromStr,
)]
pub struct Name(pub Vec<String>);
pub struct Name(Vec<String>);

impl Name {
/// Number of labels in the name (e.g., "vm1.test.mesh" has 3 labels).
Expand All @@ -38,7 +38,7 @@ impl Name {
#[must_use]
fn first_label(&self) -> &str {
// Labels are stored in reverse order, so the first label is last
self.0.last().expect("Name always has at least one label")
self.0.last().assert()
}

/// Check if this name starts with the given prefix.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/adhoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ pub(crate) fn is_valid_mesh(pattern: &NamePattern) -> bool {
return false;
};

base.0.len() == 2
base.label_count() == 2
}

#[cfg(test)]
Expand Down
16 changes: 7 additions & 9 deletions src/trust_engine_bench/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ impl NodeFactory {
trusted: bool,
) -> Node {
let id = self.allocate_id();
let name = child_name(parent_namespace, child_label(id, trusted));
let label = child_label(id, trusted);
let name = child_name(parent_namespace, &label);
Node {
id,
children: Vec::new(),
Expand All @@ -83,7 +84,8 @@ impl NodeFactory {
trusted: bool,
) -> Node {
let id = self.allocate_id();
let mesh_name = child_name(parent_namespace, child_label(id, trusted));
let label = child_label(id, trusted);
let mesh_name = child_name(parent_namespace, &label);
Node {
id,
children: Vec::new(),
Expand Down Expand Up @@ -177,9 +179,7 @@ impl Node {
}

fn root_identity_name(mesh_name: &Name) -> Name {
let mut labels = mesh_name.0.clone();
labels.push("root".to_string());
Name(labels)
format!("root.{mesh_name}").parse().assert()
}

fn child_label(id: NodeId, trusted: bool) -> String {
Expand All @@ -190,8 +190,6 @@ fn child_label(id: NodeId, trusted: bool) -> String {
}
}

fn child_name(parent_namespace: &Name, label: String) -> Name {
let mut labels = parent_namespace.0.clone();
labels.push(label);
Name(labels)
fn child_name(parent_namespace: &Name, label: &str) -> Name {
format!("{label}.{parent_namespace}").parse().assert()
}
Loading