pub fn generate_metadata_xml(metadata: SamlMetadata) -> String {
    let mut buffer = Vec::new();
    let mut writer = EmitterConfig::new()
        .perform_indent(true)
        .write_document_declaration(false)
        .create_writer(&mut buffer);

    write_event(
        XmlEvent::start_element(("md", "EntityDescriptor"))
            .attr("xmlns:md", "urn:oasis:names:tc:SAML:2.0:metadata")
            .attr("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#")
            .attr("entityID", &metadata.entity_id)
            .into(),
        &mut writer,
    );

    write_event(
        XmlEvent::start_element(("md", "IDPSSODescriptor"))
            .attr(
                "protocolSupportEnumeration",
                "urn:oasis:names:tc:SAML:2.0:protocol",
            )
            .into(),
        &mut writer,
    );

    if let Some(value) = &metadata.x509_certificate {
        let base64_encoded_certificate = value.get_as_pem_string(false);
        xml_add_certificate("signing", &base64_encoded_certificate, &mut writer);
        // xml_add_certificate("encryption", &base64_encoded_certificate, &mut writer);
    };

    write_event(
        XmlEvent::start_element(("md", "SingleLogoutService"))
            // TODO: make the binding configurable, when we support something else 🤔
            .attr(
                "Binding",
                "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
            )
            .attr("Location", metadata.logout_url().as_str())
            .into(),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);

    write_event(
        XmlEvent::start_element(("md", "NameIDFormat")).into(),
        &mut writer,
    );
    write_event(
        // TODO: nameid-format should definitely be configurable
        XmlEvent::characters(&"urn:oasis:names:tc:SAML:2.0:nameid-format:transient"),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);

    write_event(
        XmlEvent::start_element(("md", "SingleSignOnService"))
            // TODO: make the binding configurable, when we support something else 🤔
            .attr(
                "Binding",
                "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
            )
            .attr("Location", metadata.redirect_url().as_str())
            .into(),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);

    // end md:IDPSSODescriptor
    write_event(XmlEvent::end_element().into(), &mut writer);

    write_event(
        XmlEvent::start_element(("md", "ContactPerson"))
            // TODO: be able to enumerate technical contacts in IdP metadta
            .attr("contactType", "technical")
            .into(),
        &mut writer,
    );

    write_event(
        XmlEvent::start_element(("md", "GivenName")).into(),
        &mut writer,
    );
    write_event(
        // TODO: md:contactperson name should be configurable
        XmlEvent::characters(&"Admin"),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);

    write_event(
        XmlEvent::start_element(("md", "EmailAddress")).into(),
        &mut writer,
    );
    write_event(
        // TODO: md:contactperson EmailAddress should be configurable
        XmlEvent::characters(&"mailto:admin@example.com"),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);

    // end md:ContactPerson
    write_event(XmlEvent::end_element().into(), &mut writer);

    // end md:EntityDescriptor
    write_event(XmlEvent::end_element().into(), &mut writer);

    // TODO: figure out if we really need that prepended silliness '<?xml version=\"1.0\"?>'
    format!("<?xml version=\"1.0\"?>\n{}", from_utf8(&buffer).unwrap())
}
/// Generates the XML For a metadata file
///
/// Current response data is based on the data returned from  <https://samltest.id/saml/idp>
Generates the XML For a metadata file
Current response data is based on the data returned from
Generates the XML For a metadata file Current response data is based on the data returned from
pub fn generate_metadata_xml(metadata: SamlMetadata) -> String {
    let mut buffer = Vec::new();
    let mut writer = EmitterConfig::new()
        .perform_indent(true)
        .write_document_declaration(false)
        .create_writer(&mut buffer);
    write_event(
        XmlEvent::start_element(("md", "EntityDescriptor"))
            .attr("xmlns:md", "urn:oasis:names:tc:SAML:2.0:metadata")
            .attr("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#")
            .attr("entityID", &metadata.entity_id)
            .into(),
        &mut writer,
    );
    write_event(
        XmlEvent::start_element(("md", "IDPSSODescriptor"))
            .attr(
                "protocolSupportEnumeration",
                "urn:oasis:names:tc:SAML:2.0:protocol",
            )
            .into(),
        &mut writer,
    );
    if let Some(value) = &metadata.x509_certificate {
        let base64_encoded_certificate = value.get_as_pem_string(false);
        xml_add_certificate("signing", &base64_encoded_certificate, &mut writer);
        // xml_add_certificate("encryption", &base64_encoded_certificate, &mut writer);
    };
    write_event(
        XmlEvent::start_element(("md", "SingleLogoutService"))
            // TODO: make the binding configurable, when we support something else 🤔
            .attr(
                "Binding",
                "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
            )
            .attr("Location", metadata.logout_url().as_str())
            .into(),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);
    write_event(
        XmlEvent::start_element(("md", "NameIDFormat")).into(),
        &mut writer,
    );
    write_event(
        // TODO: nameid-format should definitely be configurable
        XmlEvent::characters(&"urn:oasis:names:tc:SAML:2.0:nameid-format:transient"),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);
    write_event(
        XmlEvent::start_element(("md", "SingleSignOnService"))
            // TODO: make the binding configurable, when we support something else 🤔
            .attr(
                "Binding",
                "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
            )
            .attr("Location", metadata.redirect_url().as_str())
            .into(),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);
    // end md:IDPSSODescriptor
    write_event(XmlEvent::end_element().into(), &mut writer);
    write_event(
        XmlEvent::start_element(("md", "ContactPerson"))
            // TODO: be able to enumerate technical contacts in IdP metadta
            .attr("contactType", "technical")
            .into(),
        &mut writer,
    );
    write_event(
        XmlEvent::start_element(("md", "GivenName")).into(),
        &mut writer,
    );
    write_event(
        // TODO: md:contactperson name should be configurable
        XmlEvent::characters(&"Admin"),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);
    write_event(
        XmlEvent::start_element(("md", "EmailAddress")).into(),
        &mut writer,
    );
    write_event(
        // TODO: md:contactperson EmailAddress should be configurable
        XmlEvent::characters(&"mailto:admin@example.com"),
        &mut writer,
    );
    write_event(XmlEvent::end_element().into(), &mut writer);
    // end md:ContactPerson
    write_event(XmlEvent::end_element().into(), &mut writer);
    // end md:EntityDescriptor
    write_event(XmlEvent::end_element().into(), &mut writer);
    // TODO: figure out if we really need that prepended silliness '<?xml version=\"1.0\"?>'
    format!("<?xml version=\"1.0\"?>\n{}", from_utf8(&buffer).unwrap())
}
pub fn generate_metadata_xml ( metadata : SamlMetadata ) -> String { let mut buffer = Vec :: new ( ) ; let mut writer = EmitterConfig :: new ( ) . perform_indent ( true ) . write_document_declaration ( false ) . create_writer ( & mut buffer ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . attr ( " " , " " ) . attr ( " " , " " ) . attr ( " " , & metadata . entity_id ) . into ( ) , & mut writer , ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . attr ( " " , " " , ) . into ( ) , & mut writer , ) ; if let Some ( value ) = & metadata . x509_certificate { let base64_encoded_certificate = value . get_as_pem_string ( false ) ; xml_add_certificate ( " " , & base64_encoded_certificate , & mut writer ) ; // xml_add_certificate("encryption", &base64_encoded_certificate, &mut writer); } ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) // TODO: make the binding configurable, when we support something else 🤔 . attr ( " " , " " , ) . attr ( " " , metadata . logout_url ( ) . as_str ( ) ) . into ( ) , & mut writer , ) ; write_event ( XmlEvent :: end_element ( ) . into ( ) , & mut writer ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . into ( ) , & mut writer , ) ; write_event ( // TODO: nameid-format should definitely be configurable XmlEvent :: characters ( & " " ) , & mut writer , ) ; write_event ( XmlEvent :: end_element ( ) . into ( ) , & mut writer ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) // TODO: make the binding configurable, when we support something else 🤔 . attr ( " " , " " , ) . attr ( " " , metadata . redirect_url ( ) . as_str ( ) ) . into ( ) , & mut writer , ) ; write_event ( XmlEvent :: end_element ( ) . into ( ) , & mut writer ) ; // end md:IDPSSODescriptor write_event ( XmlEvent :: end_element ( ) . into ( ) , & mut writer ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) // TODO: be able to enumerate technical contacts in IdP metadta . attr ( " " , " " ) . into ( ) , & mut writer , ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . into ( ) , & mut writer , ) ; write_event ( // TODO: md:contactperson name should be configurable XmlEvent :: characters ( & " " ) , & mut writer , ) ; write_event ( XmlEvent :: end_element ( ) . into ( ) , & mut writer ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . into ( ) , & mut writer , ) ; write_event ( // TODO: md:contactperson EmailAddress should be configurable XmlEvent :: characters ( & " " ) , & mut writer , ) ; write_event ( XmlEvent :: end_element ( ) . into ( ) , & mut writer ) ; // end md:ContactPerson write_event ( XmlEvent :: end_element ( ) . into ( ) , & mut writer ) ; // end md:EntityDescriptor write_event ( XmlEvent :: end_element ( ) . into ( ) , & mut writer ) ; // TODO: figure out if we really need that prepended silliness '<?xml version=\"1.0\"?>' format ! ( " \" \" \n " from_utf8 ( buffer ) unwrap ( ) ) }
Generates the XML For a metadata file
Current response data is based on the data returned from  <https://samltest.id/saml/idp>
Generates the XML For a metadata file Current response data is based on the data returned from <https : // samltest . id / saml / idp >
metadata
SamlMetadata
metadata
SamlMetadata