You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by bl...@apache.org on 2004/06/18 14:25:31 UTC
cvs commit: xml-security/c/src/utils XSECDOMUtils.cpp XSECDOMUtils.hpp
blautenb 2004/06/18 05:25:31
Modified: c/src/utils XSECDOMUtils.cpp XSECDOMUtils.hpp
Log:
Id Generation
Revision Changes Path
1.20 +52 -1 xml-security/c/src/utils/XSECDOMUtils.cpp
Index: XSECDOMUtils.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/utils/XSECDOMUtils.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- XSECDOMUtils.cpp 16 Apr 2004 12:07:23 -0000 1.19
+++ XSECDOMUtils.cpp 18 Jun 2004 12:25:31 -0000 1.20
@@ -677,3 +677,54 @@
}
+// --------------------------------------------------------------------------------
+// Generate Ids
+// --------------------------------------------------------------------------------
+
+void makeHexByte(XMLCh * h, unsigned char b) {
+
+ unsigned char toConvert = (b & 0xf0) >> 4;
+
+ if (toConvert < 10)
+ h[0] = chDigit_0 + toConvert;
+ else
+ h[0] = chLatin_a + toConvert - 10;
+
+ toConvert = (b & 0xf);
+
+ if (toConvert < 10)
+ h[1] = chDigit_0 + toConvert;
+ else
+ h[1] = chLatin_a + toConvert - 10;
+
+}
+
+
+XMLCh * generateId(unsigned int bytes) {
+
+ unsigned char b[128];
+ XMLCh id[258];
+ unsigned int toGen = (bytes > 128 ? 16 : bytes);
+
+ // Get the appropriate amount of random data
+ if (XSECPlatformUtils::g_cryptoProvider->getRandom(b, toGen) != toGen) {
+
+ throw XSECException(XSECException::CryptoProviderError,
+ "generateId - could not obtain enough random");
+
+ }
+
+ id[0] = chLatin_I;
+
+ for (unsigned int i = 0; i < toGen; ++i) {
+
+ makeHexByte(&id[1+(i*2)], b[i]);
+
+ }
+
+ id[1+(i*2)] = chNull;
+
+ return XMLString::replicate(id);
+
+}
+
1.17 +7 -1 xml-security/c/src/utils/XSECDOMUtils.hpp
Index: XSECDOMUtils.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/utils/XSECDOMUtils.hpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XSECDOMUtils.hpp 16 Apr 2004 12:07:23 -0000 1.16
+++ XSECDOMUtils.hpp 18 Jun 2004 12:25:31 -0000 1.17
@@ -124,6 +124,12 @@
XMLCh * decodeDName(const XMLCh * toDecode);
// --------------------------------------------------------------------------------
+// Generate Ids
+// --------------------------------------------------------------------------------
+
+XMLCh * generateId(unsigned int bytes = 16);
+
+// --------------------------------------------------------------------------------
// String Functions
// --------------------------------------------------------------------------------