aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorJoelKatz <DavidJoelSchwartz@GMail.com>2011-07-25 15:13:55 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2011-09-27 19:47:34 +0200
commit4e67a6216bf3633320950117aba3566cbfd5ffda (patch)
treee5739dd58720f6d65979f158bf51eb006ce77000 /src/util.cpp
parent9a1ce869690fe87fbce169a4b685695dc9e575f6 (diff)
downloadbitcoin-4e67a6216bf3633320950117aba3566cbfd5ffda.tar.xz
Faster Base64 decoder.
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
index a5e3d30995..5b6d26bb89 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -470,6 +470,65 @@ void ParseParameters(int argc, char* argv[])
}
}
+static const int decode64_table[256]=
+{
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
+ -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
+ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+};
+
+std::string DecodeBase64(const std::string &s)
+{
+ char buf[1024];
+ if(s.length()>512) return "";
+ char *optr=buf;
+
+ int dec, mode=0, left=0;
+ size_t index=0;
+ for (int i=0; i<s.length(); i++)
+ {
+ dec=decode64_table[s[i]];
+ if(dec==-1) break;
+ switch(mode)
+ {
+ case 0: // we have no bits and get 6
+ left = dec;
+ mode = 1;
+ break;
+
+ case 1: // we have 6 bits and keep 4
+ *optr++ = (left<<2) | (dec>>4);
+ left = dec & 15;
+ mode = 2;
+ break;
+
+ case 2: // we have 4 bits and get 6, we keep 2
+ *optr++ = (left<<4) | (dec>>2);
+ left = dec & 3;
+ mode = 3;
+ break;
+
+ case 3: // we have 2 bits and get 6
+ *optr++ = (left<<6) | dec;
+ mode=0;
+ break;
+ }
+ }
+
+ *optr=0;
+ return buf;
+}
+
bool WildcardMatch(const char* psz, const char* mask)