Skip to content

Commit

Permalink
(xmlsec-core) Add RSA MGF1 and digest template API
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikdonner authored Feb 18, 2025
1 parent f481681 commit c3d32c5
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/xmlsec/templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
78 changes: 78 additions & 0 deletions src/templates.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c3d32c5

Please sign in to comment.