mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-28 15:39:12 +00:00
Im provements in base64.hpp
This commit is contained in:
parent
da6d4932c3
commit
2290c8733a
5 changed files with 134 additions and 25 deletions
48
include/jwt/test/test_base64.cc
Normal file
48
include/jwt/test/test_base64.cc
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include "jwt/base64.hpp"
|
||||
|
||||
void base64_test_encode()
|
||||
{
|
||||
std::string input = "ArunMu";
|
||||
std::string output = jwt::base64_encode(input.c_str(), input.length());
|
||||
assert (output == "QXJ1bk11");
|
||||
|
||||
input = "Something really strange!!";
|
||||
output = jwt::base64_encode(input.c_str(), input.length());
|
||||
assert (output == "U29tZXRoaW5nIHJlYWxseSBzdHJhbmdlISE=");
|
||||
|
||||
input = "Do you want to know something more stranger ????";
|
||||
output = jwt::base64_encode(input.c_str(), input.length());
|
||||
assert (output == "RG8geW91IHdhbnQgdG8ga25vdyBzb21ldGhpbmcgbW9yZSBzdHJhbmdlciA/Pz8/");
|
||||
|
||||
input = R"({"a" : "b", "c" : [1,2,3,4,5]})";
|
||||
output = jwt::base64_encode(input.c_str(), input.length());
|
||||
assert (output == "eyJhIiA6ICJiIiwgImMiIDogWzEsMiwzLDQsNV19");
|
||||
}
|
||||
|
||||
void base64_test_decode()
|
||||
{
|
||||
std::string input = "QXJ1bk11";
|
||||
std::string output = jwt::base64_decode(input.c_str(), input.length());
|
||||
assert (output == "ArunMu");
|
||||
|
||||
input = "U29tZXRoaW5nIHJlYWxseSBzdHJhbmdlISE=";
|
||||
output = jwt::base64_decode(input.c_str(), input.length());
|
||||
assert (output == "Something really strange!!");
|
||||
|
||||
input = "RG8geW91IHdhbnQgdG8ga25vdyBzb21ldGhpbmcgbW9yZSBzdHJhbmdlciA/Pz8/";
|
||||
output = jwt::base64_decode(input.c_str(), input.length());
|
||||
assert (output == "Do you want to know something more stranger ????");
|
||||
|
||||
input = "eyJhIiA6ICJiIiwgImMiIDogWzEsMiwzLDQsNV19";
|
||||
output = jwt::base64_decode(input.c_str(), input.length());
|
||||
assert (output == R"({"a" : "b", "c" : [1,2,3,4,5]})");
|
||||
}
|
||||
|
||||
int main() {
|
||||
base64_test_encode();
|
||||
base64_test_decode();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue