Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from benthecarman/feature_http_auth
Feature http auth
- Loading branch information
Showing
10 changed files
with
125 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <string> | ||
#include <vector> | ||
|
||
std::string base64_encode(const std::string &in) | ||
{ | ||
std::string out; | ||
|
||
int val = 0, valb = -6; | ||
for (unsigned char c : in) | ||
{ | ||
val = (val << 8) + c; | ||
valb += 8; | ||
while (valb >= 0) | ||
{ | ||
out.push_back("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(val >> valb) & 0x3F]); | ||
valb -= 6; | ||
} | ||
} | ||
if (valb > -6) | ||
out.push_back("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[((val << 8) >> (valb + 8)) & 0x3F]); | ||
while (out.size() % 4) | ||
out.push_back('='); | ||
return out; | ||
} | ||
|
||
std::string base64_decode(const std::string &in) | ||
{ | ||
std::string out; | ||
|
||
std::vector<int> T(256, -1); | ||
for (int i = 0; i < 64; i++) | ||
T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i; | ||
|
||
int val = 0, valb = -8; | ||
for (unsigned char c : in) | ||
{ | ||
if (T[c] == -1) | ||
break; | ||
val = (val << 6) + T[c]; | ||
valb += 6; | ||
if (valb >= 0) | ||
{ | ||
out.push_back(char((val >> valb) & 0xFF)); | ||
valb -= 8; | ||
} | ||
} | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef BASE64_H | ||
#define BASE64_H | ||
|
||
std::string base64_encode(const std::string &); | ||
std::string base64_decode(const std::string &); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters