aboutsummaryrefslogtreecommitdiff
path: root/src/formatter.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-08-04 05:24:13 +0000
committerMike Buland <eichlan@xagasoft.com>2009-08-04 05:24:13 +0000
commit9e48c6f7d602364eb1c18de7e1e4c00e4852839c (patch)
tree0f4ba529a0d58453227b7cddc429ed97494a14ef /src/formatter.h
parent6e6402825bcd6021d62fd2eb8a0669641fe9c266 (diff)
downloadlibbu++-9e48c6f7d602364eb1c18de7e1e4c00e4852839c.tar.gz
libbu++-9e48c6f7d602364eb1c18de7e1e4c00e4852839c.tar.bz2
libbu++-9e48c6f7d602364eb1c18de7e1e4c00e4852839c.tar.xz
libbu++-9e48c6f7d602364eb1c18de7e1e4c00e4852839c.zip
***IMPORTANT*** The function Bu::Md5::getResult no longer returns a hex string,
it returns the raw binary string that makes up the md5 sum, this matches the original goal of the API and makes the whole system more general and transportable. I have added a handy helper function named getHexResult that will return the same classic hex md5 string we're used to, change anything in your code that uses getResult to getHexResult now. I've also added a handy function to the CryptoHash to write the result to a stream, writeResult. I've fixed some more things in the formatter, and added a cryptPass function that works very much like the system crypt function, md5 and base64. If I knew more about the glibc implementation I could probably make them compatible. For now there are some subtle differences in the formatting and the salting algorithm, also the output mantains it's base64 trailer (==) wheras the system function chops those off. There's also another helper that will only work on linux for now, that only takes the password, and generates a salt for you using urandom.
Diffstat (limited to 'src/formatter.h')
-rw-r--r--src/formatter.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/formatter.h b/src/formatter.h
index 8bb8e08..9f407a4 100644
--- a/src/formatter.h
+++ b/src/formatter.h
@@ -134,6 +134,7 @@ namespace Bu
134 { 134 {
135 // This code is taken from Nango, hopefully we can make it better. 135 // This code is taken from Nango, hopefully we can make it better.
136 bool bNeg = i<0; 136 bool bNeg = i<0;
137 char cBase = fLast.bCaps?'A':'a';
137 char buf[sizeof(type)*8+1]; 138 char buf[sizeof(type)*8+1];
138 if( bNeg ) i = -i; 139 if( bNeg ) i = -i;
139 if( fLast.uRadix < 2 || fLast.uRadix > 36 ) 140 if( fLast.uRadix < 2 || fLast.uRadix > 36 )
@@ -146,7 +147,7 @@ namespace Bu
146 { 147 {
147 int c = i%fLast.uRadix; 148 int c = i%fLast.uRadix;
148 i /= fLast.uRadix; 149 i /= fLast.uRadix;
149 buf[j] = (char)((c<10)?('0'+c):('A'+c-10)); 150 buf[j] = (char)((c<10)?('0'+c):(cBase+c-10));
150 if( i == 0 ) 151 if( i == 0 )
151 { 152 {
152 if( bNeg ) buf[--j] = '-'; 153 if( bNeg ) buf[--j] = '-';
@@ -164,6 +165,7 @@ namespace Bu
164 { 165 {
165 // This code is taken from Nango, hopefully we can make it better. 166 // This code is taken from Nango, hopefully we can make it better.
166 char buf[sizeof(type)*8+1]; 167 char buf[sizeof(type)*8+1];
168 char cBase = fLast.bCaps?'A':'a';
167 if( fLast.uRadix < 2 || fLast.uRadix > 36 ) 169 if( fLast.uRadix < 2 || fLast.uRadix > 36 )
168 { 170 {
169 usedFormat(); 171 usedFormat();
@@ -174,7 +176,7 @@ namespace Bu
174 { 176 {
175 int c = i%fLast.uRadix; 177 int c = i%fLast.uRadix;
176 i /= fLast.uRadix; 178 i /= fLast.uRadix;
177 buf[j] = (char)((c<10)?('0'+c):('A'+c-10)); 179 buf[j] = (char)((c<10)?('0'+c):(cBase+c-10));
178 if( i == 0 ) 180 if( i == 0 )
179 { 181 {
180 if( fLast.bPlus ) buf[--j] = '+'; 182 if( fLast.bPlus ) buf[--j] = '+';