resand 0.3.0

Read and write ARSC and AXML binary files used for Android Resources
Documentation
use resand::traits::IntoNode;
use resand_derive::{FromNode, IntoNode};

#[derive(Debug, IntoNode, FromNode)]
pub struct Certificate {
    #[resand(attr)]
    pub src: String,
}

#[derive(Debug, IntoNode, FromNode)]
pub struct TrustAnchor {
    #[resand(child, many)]
    pub certificates: Vec<Certificate>,
}

#[derive(Debug, IntoNode, FromNode)]
pub struct DebugOverride {
    #[resand(child)]
    pub trust_anchors: TrustAnchor,
}

#[derive(Debug, IntoNode, FromNode)]
pub struct BaseConfig {
    #[resand(attr)]
    pub cleartext_traffic_permitted: bool,
    #[resand(child)]
    pub trust_anchors: TrustAnchor,
}

#[derive(Debug, IntoNode, FromNode)]
#[resand(name = "network-security-config")]
pub struct NetworkSecurityConfig {
    #[resand(child)]
    pub debug_overrides: DebugOverride,
    #[resand(child)]
    pub base_config: BaseConfig,
}

/*
<network-security-config>
    <debug-overrides>
        <trust-anchors>
            <certificates src="user" />
        </trust-anchors>
    </debug-overrides>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </base-config>
</network-security-config>
*/
fn main() {
    let tree = NetworkSecurityConfig {
        debug_overrides: DebugOverride {
            trust_anchors: TrustAnchor {
                certificates: vec![Certificate {
                    src: "user".to_string(),
                }],
            },
        },
        base_config: BaseConfig {
            cleartext_traffic_permitted: true,
            trust_anchors: TrustAnchor {
                certificates: vec![
                    Certificate {
                        src: "system".to_string(),
                    },
                    Certificate {
                        src: "user".to_string(),
                    },
                ],
            },
        },
    }
    .into_tree();

    dbg!(&tree);

    let mut file = std::fs::File::create("path/to/network_security_config.xml").unwrap();
    tree.write(&mut file).unwrap();
}