mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-15 01:08:31 +00:00
JWT encoding
This commit is contained in:
parent
e7d52450d6
commit
8277e2cbd3
5 changed files with 156 additions and 3 deletions
|
@ -3,10 +3,11 @@
|
|||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include "jwt/string_view.hpp"
|
||||
|
||||
namespace jwt {
|
||||
|
||||
/*
|
||||
/*!
|
||||
* Encoding map.
|
||||
*/
|
||||
class EMap
|
||||
|
@ -30,7 +31,8 @@ private:
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
*/
|
||||
std::string base64_encode(const char* in, size_t len)
|
||||
{
|
||||
std::string result;
|
||||
|
@ -120,7 +122,8 @@ private:
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
*/
|
||||
std::string base64_decode(const char* in, size_t len)
|
||||
{
|
||||
std::string result;
|
||||
|
@ -184,6 +187,31 @@ std::string base64_decode(const char* in, size_t len)
|
|||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
*/
|
||||
void base64_uri_encode(char* data, size_t len) noexcept
|
||||
{
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
|
||||
for (; i < len; ++i) {
|
||||
switch (data[i]) {
|
||||
case '+':
|
||||
data[j++] = '-';
|
||||
break;
|
||||
case '/':
|
||||
data[j++] = '_';
|
||||
break;
|
||||
case '=':
|
||||
break;
|
||||
default:
|
||||
data[j++] = data[i];
|
||||
};
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} // END namespace jwt
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue