File: test_jwt_signature.cc

package info (click to toggle)
cpp-jwt 1.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 508 kB
  • sloc: cpp: 3,374; ansic: 33; sh: 31; makefile: 12
file content (25 lines) | stat: -rw-r--r-- 490 bytes parent folder | download | duplicates (3)
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
#include <iostream>
#include "jwt/jwt.hpp"

void basic_sign_test()
{
  // Create header
  jwt::jwt_header hdr;
  hdr = jwt::jwt_header{jwt::algorithm::HS256};

  // Create payload
  jwt::jwt_payload jp;
  jp.add_claim("sub", "1234567890");
  jp.add_claim("name", "John Doe");
  jp.add_claim("admin", true);

  jwt::jwt_signature sgn{"secret"};
  std::error_code ec{};
  auto res = sgn.encode(hdr, jp, ec);
  std::cout << res << std::endl;
}

int main() {
  basic_sign_test();
  return 0;
}