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::(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::(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)) } } } } }