MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / parse_identity_toml

Function parse_identity_toml

atomic-agent/src/identity.rs:334–359  ·  view source on GitHub ↗

Parse minimal identity info from an identity.toml file.

(content: &str)

Source from the content-addressed store, hash-verified

332
333/// Parse minimal identity info from an identity.toml file.
334fn parse_identity_toml(content: &str) -> Option<UserIdentityInfo> {
335 let mut name = None;
336 let mut email = None;
337 let mut public_key = None;
338
339 for line in content.lines() {
340 let trimmed = line.trim();
341
342 if trimmed.starts_with("name") && name.is_none() {
343 name = extract_toml_string_value(trimmed);
344 } else if trimmed.starts_with("email") && email.is_none() {
345 email = extract_toml_string_value(trimmed);
346 } else if trimmed.starts_with("public_key") && public_key.is_none() {
347 public_key = extract_toml_string_value(trimmed);
348 }
349 }
350
351 let name = name?;
352 let public_key = public_key.unwrap_or_else(|| "unknown".to_string());
353
354 Some(UserIdentityInfo {
355 name,
356 email,
357 public_key_base32: public_key,
358 })
359}
360
361/// Extract a string value from a TOML `key = "value"` line.
362fn extract_toml_string_value(line: &str) -> Option<String> {

Callers 2

load_identity_by_idFunction · 0.85

Calls 3

is_noneMethod · 0.80
linesMethod · 0.45

Tested by

no test coverage detected