private byte[] sign(final byte[] metadata) throws Exception {
        try (val is = new ByteArrayInputStream(metadata)) {
            val document = Configuration.getParserPool().parse(is);
            val documentElement = document.getDocumentElement();
            val unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(documentElement);
            val xmlObject = Objects.requireNonNull(unmarshaller).unmarshall(documentElement);
            if (xmlObject instanceof SignableXMLObject root && !root.isSigned()) {
                sign(root);
                try (var writer = Configuration.serializeSamlObject(root)) {
                    return writer.toString().getBytes(StandardCharsets.UTF_8);
                }
            }
            return metadata;
        }
    }
<p>Constructor for DefaultSAML2MetadataSigner.</p>

@param credentialProvider a {@link CredentialProvider} object
@param signatureAlgorithm a {@link String} object
@param signatureReferenceDigestMethod a {@link String} object
pac4j-saml/src/main/java/org/pac4j/saml/metadata/DefaultSAML2MetadataSigner.java