diff options
Diffstat (limited to 'src/templates.c')
-rw-r--r-- | src/templates.c | 745 |
1 files changed, 201 insertions, 544 deletions
diff --git a/src/templates.c b/src/templates.c index 88bed3dd..d0120161 100644 --- a/src/templates.c +++ b/src/templates.c @@ -1,13 +1,18 @@ -/** +/* * XML Security Library (http://www.aleksey.com/xmlsec). * - * Creating signature and encryption templates. * * This is free software; see Copyright file in the source * distribution for preciese wording. * * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved. */ +/** + * SECTION:templates + * @Short_description: XML signature and encryption template functions. + * @Stability: Stable + * + */ #include "globals.h" #include <stdlib.h> @@ -103,23 +108,15 @@ xmlSecTmplSignatureCreateNsPref(xmlDocPtr doc, xmlSecTransformId c14nMethodId, /* create Signature node itself */ signNode = xmlNewDocNode(doc, NULL, xmlSecNodeSignature, NULL); if(signNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlNewDocNode", - XMLSEC_ERRORS_R_XML_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeSignature)); + xmlSecXmlError2("xmlNewDocNode", NULL, + "node=%s", xmlSecErrorsSafeString(xmlSecNodeSignature)); return(NULL); } ns = xmlNewNs(signNode, xmlSecDSigNs, nsPrefix); if(ns == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlNewNs", - XMLSEC_ERRORS_R_XML_FAILED, - "ns=%s", - xmlSecErrorsSafeString(xmlSecDSigNs)); + xmlSecXmlError2("xmlNewNs", NULL, + "ns=%s", xmlSecErrorsSafeString(xmlSecDSigNs)); xmlFreeNode(signNode); return(NULL); } @@ -132,12 +129,7 @@ xmlSecTmplSignatureCreateNsPref(xmlDocPtr doc, xmlSecTransformId c14nMethodId, /* add SignedInfo node */ signedInfoNode = xmlSecAddChild(signNode, xmlSecNodeSignedInfo, xmlSecDSigNs); if(signedInfoNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeSignedInfo)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeSignedInfo)", NULL); xmlFreeNode(signNode); return(NULL); } @@ -145,36 +137,21 @@ xmlSecTmplSignatureCreateNsPref(xmlDocPtr doc, xmlSecTransformId c14nMethodId, /* add SignatureValue node */ cur = xmlSecAddChild(signNode, xmlSecNodeSignatureValue, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeSignatureValue)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeSignatureValue)", NULL); xmlFreeNode(signNode); return(NULL); } - /* add CanonicaizationMethod node to SignedInfo */ + /* add CanonicalizationMethod node to SignedInfo */ cur = xmlSecAddChild(signedInfoNode, xmlSecNodeCanonicalizationMethod, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeCanonicalizationMethod)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeCanonicalizationMethod)", NULL); xmlFreeNode(signNode); return(NULL); } if(xmlSetProp(cur, xmlSecAttrAlgorithm, c14nMethodId->href) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSetProp", - XMLSEC_ERRORS_R_XML_FAILED, - "name=%s,value=%s", - xmlSecErrorsSafeString(xmlSecAttrAlgorithm), - xmlSecErrorsSafeString(c14nMethodId->href)); + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrAlgorithm)); xmlFreeNode(signNode); return(NULL); } @@ -182,23 +159,13 @@ xmlSecTmplSignatureCreateNsPref(xmlDocPtr doc, xmlSecTransformId c14nMethodId, /* add SignatureMethod node to SignedInfo */ cur = xmlSecAddChild(signedInfoNode, xmlSecNodeSignatureMethod, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeSignatureMethod)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeSignatureMethod)", NULL); xmlFreeNode(signNode); return(NULL); } if(xmlSetProp(cur, xmlSecAttrAlgorithm, signMethodId->href) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSetProp", - XMLSEC_ERRORS_R_XML_FAILED, - "name=%s,value=%s", - xmlSecErrorsSafeString(xmlSecAttrAlgorithm), - xmlSecErrorsSafeString(signMethodId->href)); + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrAlgorithm)); xmlFreeNode(signNode); return(NULL); } @@ -229,22 +196,14 @@ xmlSecTmplSignatureEnsureKeyInfo(xmlNodePtr signNode, const xmlChar *id) { signValueNode = xmlSecFindChild(signNode, xmlSecNodeSignatureValue, xmlSecDSigNs); if(signValueNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeSignatureValue), - XMLSEC_ERRORS_R_NODE_NOT_FOUND, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeNotFoundError("xmlSecFindChild", signNode, + xmlSecNodeSignatureValue, NULL); return(NULL); } res = xmlSecAddNextSibling(signValueNode, xmlSecNodeKeyInfo, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddNextSibling", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeKeyInfo)); + xmlSecInternalError("xmlSecAddNextSibling(xmlSecNodeKeyInfo)", NULL); return(NULL); } } @@ -280,11 +239,8 @@ xmlSecTmplSignatureAddReference(xmlNodePtr signNode, xmlSecTransformId digestMet signedInfoNode = xmlSecFindChild(signNode, xmlSecNodeSignedInfo, xmlSecDSigNs); if(signedInfoNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeSignedInfo), - XMLSEC_ERRORS_R_NODE_NOT_FOUND, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeNotFoundError("xmlSecFindChild", signNode, + xmlSecNodeSignedInfo, NULL); return(NULL); } @@ -304,12 +260,7 @@ xmlSecTmplAddReference(xmlNodePtr parentNode, xmlSecTransformId digestMethodId, /* add Reference node */ res = xmlSecAddChild(parentNode, xmlSecNodeReference, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeReference)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeReference)", NULL); return(NULL); } @@ -327,24 +278,14 @@ xmlSecTmplAddReference(xmlNodePtr parentNode, xmlSecTransformId digestMethodId, /* add DigestMethod node and set algorithm */ cur = xmlSecAddChild(res, xmlSecNodeDigestMethod, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeDigestMethod)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeDigestMethod)", NULL); xmlUnlinkNode(res); xmlFreeNode(res); return(NULL); } if(xmlSetProp(cur, xmlSecAttrAlgorithm, digestMethodId->href) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSetProp", - XMLSEC_ERRORS_R_XML_FAILED, - "name=%s,value=%s", - xmlSecErrorsSafeString(xmlSecAttrAlgorithm), - xmlSecErrorsSafeString(digestMethodId->href)); + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrAlgorithm)); xmlUnlinkNode(res); xmlFreeNode(res); return(NULL); @@ -353,12 +294,7 @@ xmlSecTmplAddReference(xmlNodePtr parentNode, xmlSecTransformId digestMethodId, /* add DigestValue node */ cur = xmlSecAddChild(res, xmlSecNodeDigestValue, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeDigestValue)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeDigestValue)", NULL); xmlUnlinkNode(res); xmlFreeNode(res); return(NULL); @@ -388,12 +324,7 @@ xmlSecTmplSignatureAddObject(xmlNodePtr signNode, const xmlChar *id, res = xmlSecAddChild(signNode, xmlSecNodeObject, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeObject)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeObject)", NULL); return(NULL); } if(id != NULL) { @@ -424,11 +355,8 @@ xmlSecTmplSignatureGetSignMethodNode(xmlNodePtr signNode) { signedInfoNode = xmlSecFindChild(signNode, xmlSecNodeSignedInfo, xmlSecDSigNs); if(signedInfoNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeSignedInfo), - XMLSEC_ERRORS_R_NODE_NOT_FOUND, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeNotFoundError("xmlSecFindChild", signNode, + xmlSecNodeSignedInfo, NULL); return(NULL); } return(xmlSecFindChild(signedInfoNode, xmlSecNodeSignatureMethod, xmlSecDSigNs)); @@ -450,11 +378,8 @@ xmlSecTmplSignatureGetC14NMethodNode(xmlNodePtr signNode) { signedInfoNode = xmlSecFindChild(signNode, xmlSecNodeSignedInfo, xmlSecDSigNs); if(signedInfoNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeSignedInfo), - XMLSEC_ERRORS_R_NODE_NOT_FOUND, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeNotFoundError("xmlSecFindChild", signNode, + xmlSecNodeSignedInfo, NULL); return(NULL); } return(xmlSecFindChild(signedInfoNode, xmlSecNodeCanonicalizationMethod, xmlSecDSigNs)); @@ -487,39 +412,28 @@ xmlSecTmplReferenceAddTransform(xmlNodePtr referenceNode, xmlSecTransformId tran tmp = xmlSecGetNextElementNode(referenceNode->children); if(tmp == NULL) { transformsNode = xmlSecAddChild(referenceNode, xmlSecNodeTransforms, xmlSecDSigNs); + if(transformsNode == NULL) { + xmlSecInternalError("xmlSecAddChild(xmlSecNodeTransforms)", NULL); + return(NULL); + } } else { transformsNode = xmlSecAddPrevSibling(tmp, xmlSecNodeTransforms, xmlSecDSigNs); - } - if(transformsNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild or xmlSecAddPrevSibling", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeTransforms)); - return(NULL); + if(transformsNode == NULL) { + xmlSecInternalError("xmlSecAddPrevSibling(xmlSecNodeTransforms)", NULL); + return(NULL); + } } } res = xmlSecAddChild(transformsNode, xmlSecNodeTransform, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeTransform)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeTransform)", NULL); return(NULL); } if(xmlSetProp(res, xmlSecAttrAlgorithm, transformId->href) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSetProp", - XMLSEC_ERRORS_R_XML_FAILED, - "name=%s,value=%s", - xmlSecErrorsSafeString(xmlSecAttrAlgorithm), - xmlSecErrorsSafeString(transformId->href)); + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrAlgorithm)); xmlUnlinkNode(res); xmlFreeNode(res); return(NULL); @@ -547,12 +461,7 @@ xmlSecTmplObjectAddSignProperties(xmlNodePtr objectNode, const xmlChar *id, cons res = xmlSecAddChild(objectNode, xmlSecNodeSignatureProperties, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeSignatureProperties)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeSignatureProperties)", NULL); return(NULL); } if(id != NULL) { @@ -582,12 +491,7 @@ xmlSecTmplObjectAddManifest(xmlNodePtr objectNode, const xmlChar *id) { res = xmlSecAddChild(objectNode, xmlSecNodeManifest, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeManifest)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeManifest)", NULL); return(NULL); } if(id != NULL) { @@ -647,23 +551,15 @@ xmlSecTmplEncDataCreate(xmlDocPtr doc, xmlSecTransformId encMethodId, encNode = xmlNewDocNode(doc, NULL, xmlSecNodeEncryptedData, NULL); if(encNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlNewDocNode", - XMLSEC_ERRORS_R_XML_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeEncryptedData)); + xmlSecXmlError2("xmlNewDocNode", NULL, + "node=%s", xmlSecErrorsSafeString(xmlSecNodeEncryptedData)); return(NULL); } ns = xmlNewNs(encNode, xmlSecEncNs, NULL); if(ns == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlNewNs", - XMLSEC_ERRORS_R_XML_FAILED, - "ns=%s", - xmlSecErrorsSafeString(xmlSecEncNs)); + xmlSecXmlError2("xmlNewNs", NULL, + "ns=%s", xmlSecErrorsSafeString(xmlSecEncNs)); return(NULL); } xmlSetNs(encNode, ns); @@ -699,22 +595,12 @@ xmlSecTmplPrepareEncData(xmlNodePtr parentNode, xmlSecTransformId encMethodId) { if(encMethodId != NULL) { cur = xmlSecAddChild(parentNode, xmlSecNodeEncryptionMethod, xmlSecEncNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeEncryptionMethod)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeEncryptionMethod)", NULL); return(-1); } if(xmlSetProp(cur, xmlSecAttrAlgorithm, encMethodId->href) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSetProp", - XMLSEC_ERRORS_R_XML_FAILED, - "name=%s,value=%s", - xmlSecErrorsSafeString(xmlSecAttrAlgorithm), - xmlSecErrorsSafeString(encMethodId->href)); + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrAlgorithm)); return(-1); } } @@ -722,12 +608,7 @@ xmlSecTmplPrepareEncData(xmlNodePtr parentNode, xmlSecTransformId encMethodId) { /* and CipherData node */ cur = xmlSecAddChild(parentNode, xmlSecNodeCipherData, xmlSecEncNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeCipherData)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeCipherData)", NULL); return(-1); } @@ -757,22 +638,14 @@ xmlSecTmplEncDataEnsureKeyInfo(xmlNodePtr encNode, const xmlChar* id) { cipherDataNode = xmlSecFindChild(encNode, xmlSecNodeCipherData, xmlSecEncNs); if(cipherDataNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeCipherData), - XMLSEC_ERRORS_R_NODE_NOT_FOUND, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeNotFoundError("xmlSecFindChild", encNode, + xmlSecNodeCipherData, NULL); return(NULL); } res = xmlSecAddPrevSibling(cipherDataNode, xmlSecNodeKeyInfo, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddPrevSibling", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeKeyInfo)); + xmlSecInternalError("xmlSecAddPrevSibling(xmlSecNodeKeyInfo)", NULL); return(NULL); } } @@ -803,12 +676,7 @@ xmlSecTmplEncDataEnsureEncProperties(xmlNodePtr encNode, const xmlChar *id) { if(res == NULL) { res = xmlSecAddChild(encNode, xmlSecNodeEncryptionProperties, xmlSecEncNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeEncryptionProperties)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeEncryptionProperties)", NULL); return(NULL); } } @@ -842,22 +710,13 @@ xmlSecTmplEncDataAddEncProperty(xmlNodePtr encNode, const xmlChar *id, const xml encProps = xmlSecTmplEncDataEnsureEncProperties(encNode, NULL); if(encProps == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecTmplEncDataEnsureEncProperties", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecTmplEncDataEnsureEncProperties", NULL); return(NULL); } res = xmlSecAddChild(encProps, xmlSecNodeEncryptionProperty, xmlSecEncNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeEncryptionProperty)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeEncryptionProperty)", NULL); return(NULL); } if(id != NULL) { @@ -888,22 +747,15 @@ xmlSecTmplEncDataEnsureCipherValue(xmlNodePtr encNode) { cipherDataNode = xmlSecFindChild(encNode, xmlSecNodeCipherData, xmlSecEncNs); if(cipherDataNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeCipherData), - XMLSEC_ERRORS_R_NODE_NOT_FOUND, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeNotFoundError("xmlSecFindChild", encNode, + xmlSecNodeCipherData, NULL); return(NULL); } /* check that we don;t have CipherReference node */ tmp = xmlSecFindChild(cipherDataNode, xmlSecNodeCipherReference, xmlSecEncNs); if(tmp != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeCipherReference), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(cipherDataNode, xmlSecNodeCipherReference, NULL); return(NULL); } @@ -911,12 +763,7 @@ xmlSecTmplEncDataEnsureCipherValue(xmlNodePtr encNode) { if(res == NULL) { res = xmlSecAddChild(cipherDataNode, xmlSecNodeCipherValue, xmlSecEncNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeCipherValue)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeCipherValue)", NULL); return(NULL); } } @@ -944,22 +791,15 @@ xmlSecTmplEncDataEnsureCipherReference(xmlNodePtr encNode, const xmlChar *uri) { cipherDataNode = xmlSecFindChild(encNode, xmlSecNodeCipherData, xmlSecEncNs); if(cipherDataNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeCipherData), - XMLSEC_ERRORS_R_NODE_NOT_FOUND, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeNotFoundError("xmlSecFindChild", encNode, + xmlSecNodeCipherData, NULL); return(NULL); } /* check that we don;t have CipherValue node */ tmp = xmlSecFindChild(cipherDataNode, xmlSecNodeCipherValue, xmlSecEncNs); if(tmp != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeCipherValue), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(cipherDataNode, xmlSecNodeCipherValue, NULL); return(NULL); } @@ -967,12 +807,7 @@ xmlSecTmplEncDataEnsureCipherReference(xmlNodePtr encNode, const xmlChar *uri) { if(res == NULL) { res = xmlSecAddChild(cipherDataNode, xmlSecNodeCipherReference, xmlSecEncNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeCipherReference)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeCipherReference)", NULL); return(NULL); } } @@ -988,7 +823,7 @@ xmlSecTmplEncDataEnsureCipherReference(xmlNodePtr encNode, const xmlChar *uri) { * xmlSecTmplEncDataGetEncMethodNode: * @encNode: the pointer to <enc:EcnryptedData /> node. * - * Gets pointer to <enc:EncrytpionMethod/> node. + * Gets pointer to <enc:EncryptionMethod/> node. * * Returns: pointer to <enc:EncryptionMethod /> node or NULL if an error occurs. */ @@ -1025,35 +860,20 @@ xmlSecTmplCipherReferenceAddTransform(xmlNodePtr cipherReferenceNode, if(transformsNode == NULL) { transformsNode = xmlSecAddChild(cipherReferenceNode, xmlSecNodeTransforms, xmlSecEncNs); if(transformsNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeTransforms)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeTransforms)", NULL); return(NULL); } } res = xmlSecAddChild(transformsNode, xmlSecNodeTransform, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeTransform)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeTransform)", NULL); return(NULL); } if(xmlSetProp(res, xmlSecAttrAlgorithm, transformId->href) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSetProp", - XMLSEC_ERRORS_R_XML_FAILED, - "name=%s,value=%s", - xmlSecErrorsSafeString(xmlSecAttrAlgorithm), - xmlSecErrorsSafeString(transformId->href)); + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrAlgorithm)); xmlUnlinkNode(res); xmlFreeNode(res); return(NULL); @@ -1089,36 +909,21 @@ xmlSecTmplReferenceListAddDataReference(xmlNodePtr encNode, const xmlChar *uri) if(refListNode == NULL) { refListNode = xmlSecAddChild(encNode, xmlSecNodeReferenceList, xmlSecEncNs); if(refListNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeReferenceList)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeReferenceList)", NULL); return(NULL); } } res = xmlSecAddChild(refListNode, xmlSecNodeDataReference, xmlSecEncNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeDataReference)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeDataReference)", NULL); return(NULL); } if(uri != NULL) { if(xmlSetProp(res, xmlSecAttrURI, uri) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSetProp", - XMLSEC_ERRORS_R_XML_FAILED, - "name=%s,value=%s", - xmlSecErrorsSafeString(xmlSecAttrURI), - xmlSecErrorsSafeString(uri)); + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrURI)); xmlUnlinkNode(res); xmlFreeNode(res); return(NULL); @@ -1148,36 +953,21 @@ xmlSecTmplReferenceListAddKeyReference(xmlNodePtr encNode, const xmlChar *uri) { if(refListNode == NULL) { refListNode = xmlSecAddChild(encNode, xmlSecNodeReferenceList, xmlSecEncNs); if(refListNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeReferenceList)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeReferenceList)", NULL); return(NULL); } } res = xmlSecAddChild(refListNode, xmlSecNodeKeyReference, xmlSecEncNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeKeyReference)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeKeyReference)", NULL); return(NULL); } if(uri != NULL) { if(xmlSetProp(res, xmlSecAttrURI, uri) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSetProp", - XMLSEC_ERRORS_R_XML_FAILED, - "name=%s,value=%s", - xmlSecErrorsSafeString(xmlSecAttrURI), - xmlSecErrorsSafeString(uri)); + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrURI)); xmlUnlinkNode(res); xmlFreeNode(res); return(NULL); @@ -1207,21 +997,21 @@ xmlSecTmplReferenceListAddKeyReference(xmlNodePtr encNode, const xmlChar *uri) { xmlNodePtr xmlSecTmplKeyInfoAddKeyName(xmlNodePtr keyInfoNode, const xmlChar* name) { xmlNodePtr res; + int ret; xmlSecAssert2(keyInfoNode != NULL, NULL); res = xmlSecAddChild(keyInfoNode, xmlSecNodeKeyName, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeKeyName)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeKeyName)", NULL); return(NULL); } if(name != NULL) { - xmlSecNodeEncodeAndSetContent(res, name); + ret = xmlSecNodeEncodeAndSetContent(res, name); + if(ret < 0) { + xmlSecInternalError("xmlSecNodeEncodeAndSetContent", NULL); + return(NULL); + } } return(res); } @@ -1243,12 +1033,7 @@ xmlSecTmplKeyInfoAddKeyValue(xmlNodePtr keyInfoNode) { res = xmlSecAddChild(keyInfoNode, xmlSecNodeKeyValue, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeKeyValue)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeKeyValue)", NULL); return(NULL); } @@ -1272,12 +1057,7 @@ xmlSecTmplKeyInfoAddX509Data(xmlNodePtr keyInfoNode) { res = xmlSecAddChild(keyInfoNode, xmlSecNodeX509Data, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeX509Data)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeX509Data)", NULL); return(NULL); } @@ -1304,12 +1084,7 @@ xmlSecTmplKeyInfoAddRetrievalMethod(xmlNodePtr keyInfoNode, const xmlChar *uri, res = xmlSecAddChild(keyInfoNode, xmlSecNodeRetrievalMethod, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeRetrievalMethod)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeRetrievalMethod)", NULL); return(NULL); } @@ -1346,35 +1121,20 @@ xmlSecTmplRetrievalMethodAddTransform(xmlNodePtr retrMethodNode, xmlSecTransform if(transformsNode == NULL) { transformsNode = xmlSecAddChild(retrMethodNode, xmlSecNodeTransforms, xmlSecDSigNs); if(transformsNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeTransforms)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeTransforms)", NULL); return(NULL); } } res = xmlSecAddChild(transformsNode, xmlSecNodeTransform, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeTransform)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeTransform)", NULL); return(NULL); } if(xmlSetProp(res, xmlSecAttrAlgorithm, transformId->href) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSetProp", - XMLSEC_ERRORS_R_XML_FAILED, - "name=%s,value=%s", - xmlSecErrorsSafeString(xmlSecAttrAlgorithm), - xmlSecErrorsSafeString(transformId->href)); + xmlSecXmlError2("xmlSetProp", NULL, + "name=%s", xmlSecErrorsSafeString(xmlSecAttrAlgorithm)); xmlUnlinkNode(res); xmlFreeNode(res); return(NULL); @@ -1408,12 +1168,7 @@ xmlSecTmplKeyInfoAddEncryptedKey(xmlNodePtr keyInfoNode, xmlSecTransformId encMe /* we allow multiple encrypted key elements */ encKeyNode = xmlSecAddChild(keyInfoNode, xmlSecNodeEncryptedKey, xmlSecEncNs); if(encKeyNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeEncryptedKey)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeEncryptedKey)", NULL); return(NULL); } @@ -1458,22 +1213,13 @@ xmlSecTmplX509DataAddIssuerSerial(xmlNodePtr x509DataNode) { cur = xmlSecFindChild(x509DataNode, xmlSecNodeX509IssuerSerial, xmlSecDSigNs); if(cur != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeX509IssuerSerial), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(x509DataNode, xmlSecNodeX509IssuerSerial, NULL); return(NULL); } cur = xmlSecAddChild(x509DataNode, xmlSecNodeX509IssuerSerial, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeX509IssuerSerial)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeX509IssuerSerial)", NULL); return(NULL); } @@ -1492,35 +1238,29 @@ xmlSecTmplX509DataAddIssuerSerial(xmlNodePtr x509DataNode) { */ xmlNodePtr xmlSecTmplX509IssuerSerialAddIssuerName(xmlNodePtr x509IssuerSerialNode, const xmlChar* issuerName) { - xmlNodePtr res; - - xmlSecAssert2(x509IssuerSerialNode != NULL, NULL); + xmlNodePtr res; + int ret; - if(xmlSecFindChild(x509IssuerSerialNode, xmlSecNodeX509IssuerName, - xmlSecDSigNs) != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeX509IssuerName), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecAssert2(x509IssuerSerialNode != NULL, NULL); + if(xmlSecFindChild(x509IssuerSerialNode, xmlSecNodeX509IssuerName, xmlSecDSigNs) != NULL) { + xmlSecNodeAlreadyPresentError(x509IssuerSerialNode, xmlSecNodeX509IssuerName, NULL); return(NULL); - } + } - res = xmlSecAddChild(x509IssuerSerialNode, xmlSecNodeX509IssuerName, xmlSecDSigNs); + res = xmlSecAddChild(x509IssuerSerialNode, xmlSecNodeX509IssuerName, xmlSecDSigNs); if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeX509IssuerName)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeX509IssuerName)", NULL); return(NULL); } - if (issuerName != NULL) { - xmlSecNodeEncodeAndSetContent(res, issuerName); - } - return(res); + if (issuerName != NULL) { + ret = xmlSecNodeEncodeAndSetContent(res, issuerName); + if(ret < 0) { + xmlSecInternalError("xmlSecNodeEncodeAndSetContent", NULL); + return(NULL); + } + } + return(res); } /** @@ -1535,35 +1275,30 @@ xmlSecTmplX509IssuerSerialAddIssuerName(xmlNodePtr x509IssuerSerialNode, const x */ xmlNodePtr xmlSecTmplX509IssuerSerialAddSerialNumber(xmlNodePtr x509IssuerSerialNode, const xmlChar* serial) { - xmlNodePtr res; + xmlNodePtr res; + int ret; - xmlSecAssert2(x509IssuerSerialNode != NULL, NULL); + xmlSecAssert2(x509IssuerSerialNode != NULL, NULL); - if(xmlSecFindChild(x509IssuerSerialNode, xmlSecNodeX509SerialNumber, - xmlSecDSigNs) != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeX509SerialNumber), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); - return(NULL); - } + if(xmlSecFindChild(x509IssuerSerialNode, xmlSecNodeX509SerialNumber, xmlSecDSigNs) != NULL) { + xmlSecNodeAlreadyPresentError(x509IssuerSerialNode, xmlSecNodeX509SerialNumber, NULL); + return(NULL); + } - res = xmlSecAddChild(x509IssuerSerialNode, xmlSecNodeX509SerialNumber, xmlSecDSigNs); - if(res == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeX509SerialNumber)); - return(NULL); - } + res = xmlSecAddChild(x509IssuerSerialNode, xmlSecNodeX509SerialNumber, xmlSecDSigNs); + if(res == NULL) { + xmlSecInternalError("xmlSecAddChild(xmlSecNodeX509SerialNumber)", NULL); + return(NULL); + } - if (serial != NULL) { - xmlSecNodeEncodeAndSetContent(res, serial); + if (serial != NULL) { + ret = xmlSecNodeEncodeAndSetContent(res, serial); + if(ret < 0) { + xmlSecInternalError("xmlSecNodeEncodeAndSetContent", NULL); + return(NULL); } - return(res); + } + return(res); } /** @@ -1584,22 +1319,13 @@ xmlSecTmplX509DataAddSubjectName(xmlNodePtr x509DataNode) { cur = xmlSecFindChild(x509DataNode, xmlSecNodeX509SubjectName, xmlSecDSigNs); if(cur != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeX509SubjectName), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(x509DataNode, xmlSecNodeX509SubjectName, NULL); return(NULL); } cur = xmlSecAddChild(x509DataNode, xmlSecNodeX509SubjectName, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeX509SubjectName)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeX509SubjectName)", NULL); return(NULL); } @@ -1624,22 +1350,13 @@ xmlSecTmplX509DataAddSKI(xmlNodePtr x509DataNode) { cur = xmlSecFindChild(x509DataNode, xmlSecNodeX509SKI, xmlSecDSigNs); if(cur != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeX509SKI), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(x509DataNode, xmlSecNodeX509SKI, NULL); return(NULL); } cur = xmlSecAddChild(x509DataNode, xmlSecNodeX509SKI, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeX509SKI)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeX509SKI)", NULL); return(NULL); } @@ -1665,22 +1382,13 @@ xmlSecTmplX509DataAddCertificate(xmlNodePtr x509DataNode) { cur = xmlSecFindChild(x509DataNode, xmlSecNodeX509Certificate, xmlSecDSigNs); if(cur != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeX509Certificate), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(x509DataNode, xmlSecNodeX509Certificate, NULL); return(NULL); } cur = xmlSecAddChild(x509DataNode, xmlSecNodeX509Certificate, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeX509Certificate)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeX509Certificate)", NULL); return(NULL); } @@ -1705,22 +1413,13 @@ xmlSecTmplX509DataAddCRL(xmlNodePtr x509DataNode) { cur = xmlSecFindChild(x509DataNode, xmlSecNodeX509CRL, xmlSecDSigNs); if(cur != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeX509CRL), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(x509DataNode, xmlSecNodeX509CRL, NULL); return(NULL); } cur = xmlSecAddChild(x509DataNode, xmlSecNodeX509CRL, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeX509CRL)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeX509CRL)", NULL); return(NULL); } @@ -1741,38 +1440,33 @@ xmlSecTmplX509DataAddCRL(xmlNodePtr x509DataNode) { * Creates <dsig:HMACOutputLength/> child for the HMAC transform * node @node. * - * Returns: 0 on success and a negatie value otherwise. + * Returns: 0 on success and a negative value otherwise. */ int xmlSecTmplTransformAddHmacOutputLength(xmlNodePtr transformNode, xmlSecSize bitsLen) { xmlNodePtr cur; - char buf[32]; + char buf[64]; xmlSecAssert2(transformNode != NULL, -1); xmlSecAssert2(bitsLen > 0, -1); cur = xmlSecFindChild(transformNode, xmlSecNodeHMACOutputLength, xmlSecDSigNs); if(cur != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeHMACOutputLength), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(transformNode, xmlSecNodeHMACOutputLength, NULL); return(-1); } cur = xmlSecAddChild(transformNode, xmlSecNodeHMACOutputLength, xmlSecDSigNs); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeHMACOutputLength)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeHMACOutputLength)", NULL); return(-1); } - snprintf(buf, sizeof(buf), "%u", bitsLen); +#ifdef WIN32 + sprintf_s(buf, sizeof(buf), "%lu", (unsigned long)bitsLen); +#else /* WIN32 */ + sprintf(buf, "%lu", (unsigned long)bitsLen); +#endif /* WIN32 */ xmlNodeSetContent(cur, BAD_CAST buf); return(0); } @@ -1799,32 +1493,19 @@ xmlSecTmplTransformAddRsaOaepParam(xmlNodePtr transformNode, oaepParamNode = xmlSecFindChild(transformNode, xmlSecNodeRsaOAEPparams, xmlSecEncNs); if(oaepParamNode != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeRsaOAEPparams), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(transformNode, xmlSecNodeRsaOAEPparams, NULL); return(-1); } oaepParamNode = xmlSecAddChild(transformNode, xmlSecNodeRsaOAEPparams, xmlSecEncNs); if(oaepParamNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeRsaOAEPparams)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeRsaOAEPparams)", NULL); return(-1); } base64 = xmlSecBase64Encode(buf, size, 0); if(base64 == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64Encode", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", size); + xmlSecInternalError2("xmlSecBase64Encode", NULL, "size=%d", size); return(-1); } @@ -1836,7 +1517,7 @@ xmlSecTmplTransformAddRsaOaepParam(xmlNodePtr transformNode, /** * xmlSecTmplTransformAddXsltStylesheet: * @transformNode: the pointer to <dsig:Transform/> node. - * @xslt: the XSLT transform exspression. + * @xslt: the XSLT transform expression. * * Writes the XSLT transform expression to the @node. * @@ -1852,21 +1533,13 @@ xmlSecTmplTransformAddXsltStylesheet(xmlNodePtr transformNode, const xmlChar *xs xsltDoc = xmlParseMemory((const char*)xslt, xmlStrlen(xslt)); if(xsltDoc == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlParseMemory", - XMLSEC_ERRORS_R_XML_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecXmlError("xmlParseMemory", NULL); return(-1); } ret = xmlSecReplaceContent(transformNode, xmlDocGetRootElement(xsltDoc)); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecReplaceContent", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecInternalError("xmlSecReplaceContent", NULL); xmlFreeDoc(xsltDoc); return(-1); } @@ -1896,22 +1569,14 @@ xmlSecTmplTransformAddC14NInclNamespaces(xmlNodePtr transformNode, cur = xmlSecFindChild(transformNode, xmlSecNodeInclusiveNamespaces, xmlSecNsExcC14N); if(cur != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeInclusiveNamespaces), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(transformNode, xmlSecNodeInclusiveNamespaces, NULL); return(-1); } cur = xmlSecAddChild(transformNode, xmlSecNodeInclusiveNamespaces, xmlSecNsExcC14N); if(cur == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecNodeGetName(transformNode)), - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeInclusiveNamespaces)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeInclusiveNamespaces)", + xmlSecNodeGetName(transformNode)); return(-1); } @@ -1926,7 +1591,7 @@ xmlSecTmplTransformAddC14NInclNamespaces(xmlNodePtr transformNode, * @nsList: the NULL terminated list of namespace prefix/href pairs * (optional). * - * Writes XPath transform infromation to the <dsig:Transform/> node + * Writes XPath transform information to the <dsig:Transform/> node * @node. * * Returns: 0 for success or a negative value otherwise. @@ -1935,32 +1600,29 @@ int xmlSecTmplTransformAddXPath(xmlNodePtr transformNode, const xmlChar *expression, const xmlChar **nsList) { xmlNodePtr xpathNode; + int ret; xmlSecAssert2(transformNode != NULL, -1); xmlSecAssert2(expression != NULL, -1); xpathNode = xmlSecFindChild(transformNode, xmlSecNodeXPath, xmlSecDSigNs); if(xpathNode != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeXPath), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(transformNode, xmlSecNodeXPath, NULL); return(-1); } xpathNode = xmlSecAddChild(transformNode, xmlSecNodeXPath, xmlSecDSigNs); if(xpathNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeXPath)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeXPath)", NULL); + return(-1); + } + + ret = xmlSecNodeEncodeAndSetContent(xpathNode, expression); + if(ret < 0) { + xmlSecInternalError("xmlSecNodeEncodeAndSetContent", NULL); return(-1); } - xmlSecNodeEncodeAndSetContent(xpathNode, expression); return((nsList != NULL) ? xmlSecTmplNodeWriteNsList(xpathNode, nsList) : 0); } @@ -1972,7 +1634,7 @@ xmlSecTmplTransformAddXPath(xmlNodePtr transformNode, const xmlChar *expression, * @nsList: the NULL terminated list of namespace prefix/href pairs. * (optional). * - * Writes XPath2 transform infromation to the <dsig:Transform/> node + * Writes XPath2 transform information to the <dsig:Transform/> node * @node. * * Returns: 0 for success or a negative value otherwise. @@ -1981,6 +1643,7 @@ int xmlSecTmplTransformAddXPath2(xmlNodePtr transformNode, const xmlChar* type, const xmlChar *expression, const xmlChar **nsList) { xmlNodePtr xpathNode; + int ret; xmlSecAssert2(transformNode != NULL, -1); xmlSecAssert2(type != NULL, -1); @@ -1988,17 +1651,17 @@ xmlSecTmplTransformAddXPath2(xmlNodePtr transformNode, const xmlChar* type, xpathNode = xmlSecAddChild(transformNode, xmlSecNodeXPath, xmlSecXPath2Ns); if(xpathNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeXPath)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeXPath)", NULL); return(-1); } xmlSetProp(xpathNode, xmlSecAttrFilter, type); - xmlSecNodeEncodeAndSetContent(xpathNode, expression); + ret = xmlSecNodeEncodeAndSetContent(xpathNode, expression); + if(ret < 0) { + xmlSecInternalError("xmlSecNodeEncodeAndSetContent", NULL); + return(-1); + } + return((nsList != NULL) ? xmlSecTmplNodeWriteNsList(xpathNode, nsList) : 0); } @@ -2009,7 +1672,7 @@ xmlSecTmplTransformAddXPath2(xmlNodePtr transformNode, const xmlChar* type, * @nsList: the NULL terminated list of namespace prefix/href pairs. * (optional). * - * Writes XPoniter transform infromation to the <dsig:Transform/> node + * Writes XPointer transform information to the <dsig:Transform/> node * @node. * * Returns: 0 for success or a negative value otherwise. @@ -2018,33 +1681,29 @@ int xmlSecTmplTransformAddXPointer(xmlNodePtr transformNode, const xmlChar *expression, const xmlChar **nsList) { xmlNodePtr xpointerNode; + int ret; xmlSecAssert2(expression != NULL, -1); xmlSecAssert2(transformNode != NULL, -1); xpointerNode = xmlSecFindChild(transformNode, xmlSecNodeXPointer, xmlSecXPointerNs); if(xpointerNode != NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeXPointer), - XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, - XMLSEC_ERRORS_NO_MESSAGE); + xmlSecNodeAlreadyPresentError(transformNode, xmlSecNodeXPointer, NULL); return(-1); } xpointerNode = xmlSecAddChild(transformNode, xmlSecNodeXPointer, xmlSecXPointerNs); if(xpointerNode == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAddChild", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "node=%s", - xmlSecErrorsSafeString(xmlSecNodeXPointer)); + xmlSecInternalError("xmlSecAddChild(xmlSecNodeXPointer)", NULL); return(-1); } + ret = xmlSecNodeEncodeAndSetContent(xpointerNode, expression); + if(ret < 0) { + xmlSecInternalError("xmlSecNodeEncodeAndSetContent", NULL); + return(-1); + } - xmlSecNodeEncodeAndSetContent(xpointerNode, expression); return((nsList != NULL) ? xmlSecTmplNodeWriteNsList(xpointerNode, nsList) : 0); } @@ -2058,34 +1717,32 @@ xmlSecTmplNodeWriteNsList(xmlNodePtr parentNode, const xmlChar** nsList) { xmlSecAssert2(parentNode != NULL, -1); xmlSecAssert2(nsList != NULL, -1); + /* nsList contains pairs of prefix/href with NULL at the end. We use special + "#default" prefix instead of NULL prefix */ ptr = nsList; while((*ptr) != NULL) { + /* get next prefix/href pair */ if(xmlStrEqual(BAD_CAST "#default", (*ptr))) { prefix = NULL; } else { prefix = (*ptr); } - if(*(++ptr) == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "unexpected end of ns list"); + href = *(++ptr); + if(href == NULL) { + xmlSecInvalidDataError("unexpected end of ns list", NULL); return(-1); } - href = *(ptr++); + /* create namespace node */ ns = xmlNewNs(parentNode, href, prefix); if(ns == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlNewNs", - XMLSEC_ERRORS_R_XML_FAILED, - "href=%s;prefix=%s", - xmlSecErrorsSafeString(href), - xmlSecErrorsSafeString(prefix)); + xmlSecXmlError2("xmlNewNs", NULL, + "prefix=%s", xmlSecErrorsSafeString(prefix)); return(-1); } + + /* next pair */ + ++ptr; } return(0); } |