diff --git a/include/xmlsec/templates.h b/include/xmlsec/templates.h index 827e13686..c5229b8ed 100644 --- a/include/xmlsec/templates.h +++ b/include/xmlsec/templates.h @@ -141,6 +141,10 @@ XMLSEC_EXPORT int xmlSecTmplTransformAddHmacOutputLength (xmlNodePtr tran XMLSEC_EXPORT int xmlSecTmplTransformAddRsaOaepParam (xmlNodePtr transformNode, const xmlSecByte *buf, xmlSecSize size); +XMLSEC_EXPORT int xmlSecTmplTransformAddRsaMgf (xmlNodePtr transformNode, + const xmlChar* algorithm); +XMLSEC_EXPORT int xmlSecTmplTransformAddRsaDigest (xmlNodePtr transformNode, + const xmlChar* algorithm); XMLSEC_EXPORT int xmlSecTmplTransformAddXsltStylesheet (xmlNodePtr transformNode, const xmlChar *xslt); XMLSEC_EXPORT int xmlSecTmplTransformAddC14NInclNamespaces(xmlNodePtr transformNode, diff --git a/src/templates.c b/src/templates.c index 32efdeba0..2d11b9621 100644 --- a/src/templates.c +++ b/src/templates.c @@ -1553,6 +1553,84 @@ xmlSecTmplTransformAddRsaOaepParam(xmlNodePtr transformNode, const xmlSecByte *b return(0); } +/** + * xmlSecTmplTransformAddRsaMgf: + * @transformNode: the pointer to <dsig:Transform/> node. + * @algorithm: MGF1 algorithm href. + * + * Creates <enc:MGF/> child node in the @node. + * + * Returns: 0 on success or a negative value if an error occurs. + */ +int +xmlSecTmplTransformAddRsaMgf(xmlNodePtr transformNode, + const xmlChar *algorithm) { + xmlNodePtr mgfNode; + + xmlSecAssert2(transformNode != NULL, -1); + + mgfNode = xmlSecFindChild(transformNode, xmlSecNodeRsaMGF, xmlSecEnc11Ns); + if(mgfNode != NULL) { + xmlSecNodeAlreadyPresentError(transformNode, xmlSecNodeRsaMGF, NULL); + return(-1); + } + + mgfNode = xmlSecAddChild(transformNode, xmlSecNodeRsaMGF, xmlSecEnc11Ns); + if(mgfNode == NULL) { + xmlSecInternalError("xmlSecAddChild(xmlSecNodeRsaMgf)", NULL); + return(-1); + } + + if(xmlSetProp(mgfNode, xmlSecAttrAlgorithm, algorithm) == NULL) { + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrAlgorithm)); + xmlUnlinkNode(mgfNode); + xmlFreeNode(mgfNode); + return(-1); + } + + return(0); +} + +/** + * xmlSecTmplTransformAddRsaDigest: + * @transformNode: the pointer to <dsig:Transform/> node. + * @algorithm: digest algorithm href. + * + * Creates <dsig:DigestMethod/> child node in the @node. + * + * Returns: 0 on success or a negative value if an error occurs. + */ +int +xmlSecTmplTransformAddRsaDigest(xmlNodePtr transformNode, + const xmlChar *algorithm) { + xmlNodePtr digestNode; + + xmlSecAssert2(transformNode != NULL, -1); + + digestNode = xmlSecFindChild(transformNode, xmlSecNodeDigestMethod, xmlSecDSigNs); + if(digestNode != NULL) { + xmlSecNodeAlreadyPresentError(transformNode, xmlSecNodeDigestMethod, NULL); + return(-1); + } + + digestNode = xmlSecAddChild(transformNode, xmlSecNodeDigestMethod, xmlSecDSigNs); + if(digestNode == NULL) { + xmlSecInternalError("xmlSecAddChild(xmlSecNodeDigestMethod)", NULL); + return(-1); + } + + if(xmlSetProp(digestNode, xmlSecAttrAlgorithm, algorithm) == NULL) { + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrAlgorithm)); + xmlUnlinkNode(digestNode); + xmlFreeNode(digestNode); + return(-1); + } + + return(0); +} + /** * xmlSecTmplTransformAddXsltStylesheet: * @transformNode: the pointer to <dsig:Transform/> node.