Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RSA MGF1 and digest template API #899

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading