pub fn generate_signedinfo<W: Write>(
    attr: &crate::assertion::Assertion,
    digest: &str,
    writer: &mut EventWriter<W>,
) {
    // start ds:SignedInfo
    write_event(XmlEvent::start_element(("ds", "SignedInfo")).into(), writer);
    // start CanonicalizationMethod Tag
    write_event(
        XmlEvent::start_element(("ds", "CanonicalizationMethod"))
            .attr("Algorithm", "http://www.w3.org/2001/10/xml-exc-c14n#")
            .into(),
        writer,
    );
    //end ds:CanonicalizationMethod
    write_event(XmlEvent::end_element().into(), writer);

    // https://www.w3.org/TR/xmldsig-core/#sec-SignatureMethod

    let test: String = attr.signing_algorithm.into();

    write_event(
        XmlEvent::start_element(("ds", "SignatureMethod"))
            .attr("Algorithm", &test)
            .into(),
        writer,
    );
    //end ds:Algorithm
    write_event(XmlEvent::end_element().into(), writer);

    /*
    TODO: this needs to be a reference to the ID
    5.4.2 References
    Signatures MUST contain a single <ds:Reference> containing a same-document reference to the ID
    attribute value of the root element of the assertion or protocol message being signed. For example, if the
    ID attribute value is "foo", then the URI attribute in the <ds:Reference> element MUST be "#foo".
    */
    write_event(
        XmlEvent::start_element(("ds", "Reference"))
            .attr("URI", &format!("#{}", attr.assertion_id))
            .into(),
        writer,
    );

    write_event(XmlEvent::start_element(("ds", "Transforms")).into(), writer);

    write_event(
        XmlEvent::start_element(("ds", "Transform"))
            .attr(
                "Algorithm",
                "http://www.w3.org/2000/09/xmldsig#enveloped-signature",
            )
            .into(),
        writer,
    );
    //end ds:Transform
    write_event(XmlEvent::end_element().into(), writer);

    write_event(
        XmlEvent::start_element(("ds", "Transform"))
            .attr("Algorithm", "http://www.w3.org/2001/10/xml-exc-c14n#")
            .into(),
        writer,
    );
    //end ds:Transform
    write_event(XmlEvent::end_element().into(), writer);

    //end ds:Transforms
    write_event(XmlEvent::end_element().into(), writer);

    let digestmethod: String = attr.digest_algorithm.into();

    // start ds:DigestMethod
    // <https://www.w3.org/TR/xmldsig-core/#sec-DigestMethod>
    write_event(
        XmlEvent::start_element(("ds", "DigestMethod"))
            .attr("Algorithm", &digestmethod)
            .into(),
        writer,
    );
    //end ds:DigestMethod
    write_event(XmlEvent::end_element().into(), writer);

    // <https://www.w3.org/TR/xmldsig-core/#sec-DigestValue>
    // DigestValue is an element that contains the encoded value of the digest. The digest is always encoded using base64 RFC2045.
    write_event(
        XmlEvent::start_element(("ds", "DigestValue")).into(),
        writer,
    );

    write_event(XmlEvent::characters(&digest), writer);
    //end ds:DigestValue
    write_event(XmlEvent::end_element().into(), writer);

    //end ds:Reference
    write_event(XmlEvent::end_element().into(), writer);

    //end ds:SignedInfo
    write_event(XmlEvent::end_element().into(), writer);
}
/// add a signature to the statement
add a signature to the statement
add a signature to the statement
pub fn generate_signedinfo<W: Write>(
    attr: &crate::assertion::Assertion,
    digest: &str,
    writer: &mut EventWriter<W>,
) {
    // start ds:SignedInfo
    write_event(XmlEvent::start_element(("ds", "SignedInfo")).into(), writer);
    // start CanonicalizationMethod Tag
    write_event(
        XmlEvent::start_element(("ds", "CanonicalizationMethod"))
            .attr("Algorithm", "http://www.w3.org/2001/10/xml-exc-c14n#")
            .into(),
        writer,
    );
    //end ds:CanonicalizationMethod
    write_event(XmlEvent::end_element().into(), writer);
    // https://www.w3.org/TR/xmldsig-core/#sec-SignatureMethod
    let test: String = attr.signing_algorithm.into();
    write_event(
        XmlEvent::start_element(("ds", "SignatureMethod"))
            .attr("Algorithm", &test)
            .into(),
        writer,
    );
    //end ds:Algorithm
    write_event(XmlEvent::end_element().into(), writer);
    /*
    TODO: this needs to be a reference to the ID
    5.4.2 References
    Signatures MUST contain a single <ds:Reference> containing a same-document reference to the ID
    attribute value of the root element of the assertion or protocol message being signed. For example, if the
    ID attribute value is "foo", then the URI attribute in the <ds:Reference> element MUST be "#foo".
    */
    write_event(
        XmlEvent::start_element(("ds", "Reference"))
            .attr("URI", &format!("#{}", attr.assertion_id))
            .into(),
        writer,
    );
    write_event(XmlEvent::start_element(("ds", "Transforms")).into(), writer);
    write_event(
        XmlEvent::start_element(("ds", "Transform"))
            .attr(
                "Algorithm",
                "http://www.w3.org/2000/09/xmldsig#enveloped-signature",
            )
            .into(),
        writer,
    );
    //end ds:Transform
    write_event(XmlEvent::end_element().into(), writer);
    write_event(
        XmlEvent::start_element(("ds", "Transform"))
            .attr("Algorithm", "http://www.w3.org/2001/10/xml-exc-c14n#")
            .into(),
        writer,
    );
    //end ds:Transform
    write_event(XmlEvent::end_element().into(), writer);
    //end ds:Transforms
    write_event(XmlEvent::end_element().into(), writer);
    let digestmethod: String = attr.digest_algorithm.into();
    // start ds:DigestMethod
    // <https://www.w3.org/TR/xmldsig-core/#sec-DigestMethod>
    write_event(
        XmlEvent::start_element(("ds", "DigestMethod"))
            .attr("Algorithm", &digestmethod)
            .into(),
        writer,
    );
    //end ds:DigestMethod
    write_event(XmlEvent::end_element().into(), writer);
    // <https://www.w3.org/TR/xmldsig-core/#sec-DigestValue>
    // DigestValue is an element that contains the encoded value of the digest. The digest is always encoded using base64 RFC2045.
    write_event(
        XmlEvent::start_element(("ds", "DigestValue")).into(),
        writer,
    );
    write_event(XmlEvent::characters(&digest), writer);
    //end ds:DigestValue
    write_event(XmlEvent::end_element().into(), writer);
    //end ds:Reference
    write_event(XmlEvent::end_element().into(), writer);
    //end ds:SignedInfo
    write_event(XmlEvent::end_element().into(), writer);
}
pub fn generate_signedinfo < W : Write > ( attr : & crate :: assertion :: Assertion , digest : & str , writer : & mut EventWriter < W > , ) { // start ds:SignedInfo write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . into ( ) , writer ) ; // start CanonicalizationMethod Tag write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . attr ( " " , " " ) . into ( ) , writer , ) ; //end ds:CanonicalizationMethod write_event ( XmlEvent :: end_element ( ) . into ( ) , writer ) ; // https://www.w3.org/TR/xmldsig-core/#sec-SignatureMethod let test : String = attr . signing_algorithm . into ( ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . attr ( " " , & test ) . into ( ) , writer , ) ; //end ds:Algorithm write_event ( XmlEvent :: end_element ( ) . into ( ) , writer ) ; /*
    TODO: this needs to be a reference to the ID
    5.4.2 References
    Signatures MUST contain a single <ds:Reference> containing a same-document reference to the ID
    attribute value of the root element of the assertion or protocol message being signed. For example, if the
    ID attribute value is "foo", then the URI attribute in the <ds:Reference> element MUST be "#foo".
    */ write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . attr ( " " , & format ! ( " " attr assertion_id ) ) . into ( ) , writer , ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . into ( ) , writer ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . attr ( " " , " " , ) . into ( ) , writer , ) ; //end ds:Transform write_event ( XmlEvent :: end_element ( ) . into ( ) , writer ) ; write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . attr ( " " , " " ) . into ( ) , writer , ) ; //end ds:Transform write_event ( XmlEvent :: end_element ( ) . into ( ) , writer ) ; //end ds:Transforms write_event ( XmlEvent :: end_element ( ) . into ( ) , writer ) ; let digestmethod : String = attr . digest_algorithm . into ( ) ; // start ds:DigestMethod // <https://www.w3.org/TR/xmldsig-core/#sec-DigestMethod> write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . attr ( " " , & digestmethod ) . into ( ) , writer , ) ; //end ds:DigestMethod write_event ( XmlEvent :: end_element ( ) . into ( ) , writer ) ; // <https://www.w3.org/TR/xmldsig-core/#sec-DigestValue> // DigestValue is an element that contains the encoded value of the digest. The digest is always encoded using base64 RFC2045. write_event ( XmlEvent :: start_element ( ( " " , " " ) ) . into ( ) , writer , ) ; write_event ( XmlEvent :: characters ( & digest ) , writer ) ; //end ds:DigestValue write_event ( XmlEvent :: end_element ( ) . into ( ) , writer ) ; //end ds:Reference write_event ( XmlEvent :: end_element ( ) . into ( ) , writer ) ; //end ds:SignedInfo write_event ( XmlEvent :: end_element ( ) . into ( ) , writer ) ; }
add a signature to the statement
add a signature to the statement
attr
&crate::assertion::Assertion
digest
&str
writer
&mut EventWriter<W>
attr
&crate::assertion::Assertion
digest
&str
writer
&mut EventWriter<W>