Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

DSIGConstants.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 2002 Berin Lautenbach.  All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  * 3. The end-user documentation included with the redistribution,
00019  *    if any, must include the following acknowledgment:
00020  *       "This product includes software developed by
00021  *                   Berin Lautenbach"
00022  *    Alternately, this acknowledgment may appear in the software itself,
00023  *    if and wherever such third-party acknowledgments normally appear.
00024  *
00025  * 4. The names "XSEC", "xml-security-c" and Berin Lautenbach must
00026  *    not be used to endorse or promote products derived from this
00027  *    software without prior written permission. For written
00028  *    permission, please contact berin@users.sourceforge.net.
00029  *
00030  * 5. Products derived from this software may not be called "xml-security-c",
00031  *    nor may "xml-security-c" appear in their name, without prior written
00032  *    permission of Berin Lautenbach.
00033  *
00034  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00035  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00036  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00037  * DISCLAIMED.  IN NO EVENT SHALL BERIN LAUTENBACH OR OTHER
00038  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00039  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00040  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00041  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00042  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00043  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00044  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00045  * SUCH DAMAGE.
00046  * ====================================================================
00047  */
00048 
00049 /*
00050  * XSEC
00051  *
00052  * DSIGConstants := Definitions of varius DSIG constants (mainly strings)
00053  *
00054  */
00055 
00056 #ifndef DSIGCONSTANTS_HEADER
00057 #define DSIGCONSTANTS_HEADER
00058 
00059 #include <xsec/utils/XSECSafeBuffer.hpp>
00060 
00061 // Xerces
00062 #include <xercesc/util/XMLString.hpp>
00063 
00064 // Name Spaces
00065 
00066 #define URI_ID_DSIG     "http://www.w3.org/2000/09/xmldsig#"
00067 
00068 
00069 // Hashing Algorithms
00070 
00071 #define URI_ID_SHA1     "http://www.w3.org/2000/09/xmldsig#sha1"
00072 
00073 // Transforms
00074 
00075 #define URI_ID_BASE64           "http://www.w3.org/2000/09/xmldsig#base64"
00076 #define URI_ID_XPATH            "http://www.w3.org/TR/1999/REC-xpath-19991116"
00077 #define URI_ID_XSLT             "http://www.w3.org/TR/1999/REC-xslt-19991116"
00078 #define URI_ID_ENVELOPE         "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
00079 #define URI_ID_C14N_NOC         "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
00080 #define URI_ID_C14N_COM         "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
00081 #define URI_ID_EXC_C14N_NOC     "http://www.w3.org/2001/10/xml-exc-c14n#"
00082 #define URI_ID_EXC_C14N_COM     "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
00083 #define XPATH_EXPR_ENVELOPE     "count(ancestor-or-self::dsig:Signature | \
00084                                  here()/ancestor::dsig:Signature[1]) > \
00085                                  count(ancestor-or-self::dsig:Signature)"
00086 
00087 // Signature Algorithms
00088 
00089 #define URI_ID_SIG_BASE     "http://www.w3.org/2000/09/xmldsig#"
00090 #define URI_ID_SIG_DSA      "dsa"
00091 #define URI_ID_SIG_HMAC     "hmac"
00092 #define URI_ID_SIG_SHA1     "sha1"
00093 #define URI_ID_SIG_RSA      "rsa"
00094 
00095 #define URI_ID_DSA_SHA1     "http://www.w3.org/2000/09/xmldsig#dsa-sha1"
00096 #define URI_ID_HMAC_SHA1    "http://www.w3.org/2000/09/xmldsig#hmac-sha1"
00097 #define URI_ID_RSA_SHA1     "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
00098 
00099 // General
00100 
00101 #define URI_ID_XMLNS    "http://www.w3.org/2000/xmlns/"
00102 #define URI_ID_MANIFEST "http://www.w3.org/2000/09/xmldsig#Manifest"
00103 
00104 // Enumerated Types
00105 
00106 
00107 enum canonicalizationMethod {
00108 
00109     CANON_NONE                  = 0,            // No method defined
00110     CANON_C14N_NOC              = 1,            // C14n without comments
00111     CANON_C14N_COM              = 2,            // C14n with comments
00112     CANON_C14NE_NOC             = 3,            // C14n Exclusive (without comments)
00113     CANON_C14NE_COM             = 4             // C14n Exlusive (with Comments
00114 };
00115 
00116 enum signatureMethod {
00117 
00118     SIGNATURE_NONE              = 0,            // No method defined
00119     SIGNATURE_DSA               = 1,            // DSA
00120     SIGNATURE_HMAC              = 2,            // Hash MAC
00121     SIGNATURE_RSA               = 3             // RSA
00122 };
00123 
00124 
00125 enum hashMethod {
00126 
00127     HASH_NONE                   = 0,            // No method defined
00128     HASH_SHA1                   = 1             // SHA1
00129 };
00130 
00131 enum transformType {
00132 
00133     TRANSFORM_BASE64,
00134     TRANSFORM_C14N,
00135     TRANSFORM_EXC_C14N,
00136     TRANSFORM_ENVELOPED_SIGNATURE,
00137     TRANSFORM_XPATH,
00138     TRANSFORM_XSLT
00139 
00140 };
00141 
00142 // --------------------------------------------------------------------------------
00143 //           Some utility functions
00144 // --------------------------------------------------------------------------------
00145 
00146 inline
00147 bool canonicalizationMethod2URI(safeBuffer &uri, canonicalizationMethod cm) {
00148 
00149     switch (cm) {
00150 
00151     case (CANON_C14N_NOC) :
00152 
00153         uri = URI_ID_C14N_NOC;
00154         break;
00155 
00156     case (CANON_C14N_COM) :
00157 
00158         uri = URI_ID_C14N_COM;
00159         break;
00160 
00161     case (CANON_C14NE_NOC) :
00162 
00163         uri = URI_ID_EXC_C14N_NOC;
00164         break;
00165 
00166     case (CANON_C14NE_COM) :
00167 
00168         uri = URI_ID_EXC_C14N_COM;
00169         break;
00170 
00171     default :
00172         return false;       // Unknown type
00173 
00174     }
00175 
00176     return true;
00177 
00178 }
00179 
00180 inline
00181 bool signatureHashMethod2URI(safeBuffer &uri, signatureMethod sm, hashMethod hm) {
00182 
00183     uri = URI_ID_SIG_BASE;
00184 
00185     switch (sm) {
00186 
00187     case (SIGNATURE_DSA) :
00188 
00189         uri.sbStrcatIn(URI_ID_SIG_DSA);
00190         break;
00191 
00192     case (SIGNATURE_HMAC) :
00193 
00194         uri.sbStrcatIn(URI_ID_SIG_HMAC);
00195         break;
00196 
00197     case (SIGNATURE_RSA) :
00198 
00199         uri.sbStrcatIn(URI_ID_SIG_RSA);
00200 
00201     default :
00202 
00203         return false;
00204 
00205     }
00206 
00207     uri.sbStrcatIn("-");
00208 
00209     switch (hm) {
00210 
00211     case (HASH_SHA1) :
00212 
00213         uri.sbStrcatIn(URI_ID_SIG_SHA1);
00214         break;
00215 
00216     default:
00217 
00218         return false;
00219 
00220     }
00221 
00222     return true;
00223 
00224 }
00225 
00226 inline
00227 bool hashMethod2URI(safeBuffer &uri, hashMethod hm) {
00228 
00229     switch (hm) {
00230 
00231     case (HASH_SHA1) :
00232 
00233         uri = URI_ID_SHA1;
00234         break;
00235 
00236     default:
00237         return false;
00238 
00239     }
00240 
00241     return true;
00242 
00243 }
00244 
00245 // --------------------------------------------------------------------------------
00246 //           Constant Strings Class
00247 // --------------------------------------------------------------------------------
00248 
00249 class DSIG_EXPORT DSIGConstants {
00250 
00251 public:
00252 
00253     // General strings
00254 
00255     static const XMLCh * const & s_unicodeStrEmpty;     // ""
00256     static const XMLCh * const & s_unicodeStrNL;            // "\n"
00257     static const XMLCh * const & s_unicodeStrXmlns;     // "xmlns"
00258 
00259     // DSIG Element Strings
00260     static const XMLCh * const & s_unicodeStrAlgorithm;
00261 
00262     // URI_IDs
00263     static const XMLCh * const & s_unicodeStrURIDSIG;
00264     static const XMLCh * const & s_unicodeStrURISHA1;
00265     static const XMLCh * const & s_unicodeStrURIBASE64;
00266     static const XMLCh * const & s_unicodeStrURIXPATH;
00267     static const XMLCh * const & s_unicodeStrURIXSLT;
00268     static const XMLCh * const & s_unicodeStrURIENVELOPE;
00269     static const XMLCh * const & s_unicodeStrURIC14N_NOC;
00270     static const XMLCh * const & s_unicodeStrURIC14N_COM;
00271     static const XMLCh * const & s_unicodeStrURIEXC_C14N_NOC;
00272     static const XMLCh * const & s_unicodeStrURIEXC_C14N_COM;
00273     static const XMLCh * const & s_unicodeStrURIDSA_SHA1;
00274     static const XMLCh * const & s_unicodeStrURIRSA_SHA1;
00275     static const XMLCh * const & s_unicodeStrURIHMAC_SHA1;
00276     static const XMLCh * const & s_unicodeStrURIXMLNS;
00277     static const XMLCh * const & s_unicodeStrURIMANIFEST;
00278 
00279 
00280     DSIGConstants();
00281 
00282     static void create();
00283     static void destroy();
00284 
00285 };
00286 
00287 
00288 
00289 
00290 inline
00291 const XMLCh * canonicalizationMethod2UNICODEURI(canonicalizationMethod cm) {
00292 
00293     switch (cm) {
00294 
00295     case (CANON_C14N_NOC) :
00296 
00297         return DSIGConstants::s_unicodeStrURIC14N_NOC;
00298         break;
00299 
00300     case (CANON_C14N_COM) :
00301 
00302         return DSIGConstants::s_unicodeStrURIC14N_COM;
00303         break;
00304 
00305     case (CANON_C14NE_NOC) :
00306 
00307         return DSIGConstants::s_unicodeStrURIEXC_C14N_NOC;
00308         break;
00309 
00310     case (CANON_C14NE_COM) :
00311 
00312         return DSIGConstants::s_unicodeStrURIEXC_C14N_COM;
00313         break;
00314 
00315     default :
00316         break;
00317 
00318     }
00319 
00320     return DSIGConstants::s_unicodeStrEmpty;
00321 
00322 }
00323 
00324 #endif /* DSIGCONSTANTS_HEADER */

Generated on Sat Jan 11 20:34:06 2003 for XML-Security-C by doxygen1.2.15