sharenet/frontend/wasm/src/debug.rs
continuist dc050d5e34
Some checks failed
Podman Rootless Demo / test-backend (push) Has been skipped
Podman Rootless Demo / test-frontend (push) Has been skipped
Podman Rootless Demo / build-backend (push) Failing after 1s
Podman Rootless Demo / deploy-prod (push) Has been skipped
Podman Rootless Demo / build-frontend (push) Has been skipped
Add self-sovereign passports
2025-10-20 21:15:11 -04:00

45 lines
No EOL
2 KiB
Rust

use sharenet_passport::domain::entities::PassportFile;
use serde_cbor;
pub fn debug_parse_spf(data: &[u8]) -> Result<(), String> {
// Try to parse the CBOR data
match serde_cbor::from_slice::<PassportFile>(data) {
Ok(_passport_file) => {
// Return success with file info
Ok(())
}
Err(e) => {
// Try to parse as generic CBOR value to see the structure
match serde_cbor::from_slice::<serde_cbor::Value>(data) {
Ok(value) => {
// Check if all required fields are present
if let serde_cbor::Value::Map(map) = &value {
let required_fields = [
"enc_seed", "kdf", "cipher", "salt", "nonce",
"public_key", "did", "univ_id", "created_at",
"version", "enc_user_profiles"
];
let mut missing_fields = Vec::new();
for field in &required_fields {
if !map.iter().any(|(k, _)| k == &serde_cbor::Value::Text(field.to_string())) {
missing_fields.push(*field);
}
}
if !missing_fields.is_empty() {
return Err(format!("CBOR parsing failed: {}. Missing fields: {:?}. Raw structure: {:?}", e, missing_fields, value));
} else {
return Err(format!("CBOR parsing failed: {}. All fields present but structure mismatch. Raw structure: {:?}", e, value));
}
} else {
return Err(format!("CBOR parsing failed: {}. Data is not a map. Raw structure: {:?}", e, value));
}
}
Err(e2) => {
Err(format!("CBOR parsing failed: {}. Also failed to parse as generic CBOR: {}", e, e2))
}
}
}
}
}