diff --git a/include/jwt/impl/jwt.ipp b/include/jwt/impl/jwt.ipp index a5dfe56..7e9beb0 100644 --- a/include/jwt/impl/jwt.ipp +++ b/include/jwt/impl/jwt.ipp @@ -254,7 +254,7 @@ jwt_payload& jwt_object::add_claim(const string_view name, T&& value) return payload_; } -jwt_payload& jwt_object::remove_claim(const std::string& name) +jwt_payload& jwt_object::remove_claim(const string_view name) { payload_.remove_claim(name); return payload_; diff --git a/include/jwt/jwt.hpp b/include/jwt/jwt.hpp index 8f4af64..1f2cc3c 100644 --- a/include/jwt/jwt.hpp +++ b/include/jwt/jwt.hpp @@ -199,6 +199,13 @@ public: // Exposed APIs alg_ = alg; } + /** + */ + void algo(const string_view sv) + { + alg_ = str_to_alg(sv.data()); + } + /*! */ enum algorithm algo() const noexcept @@ -305,13 +312,13 @@ public: // Exposed APIs /** */ - bool remove_claim(const std::string& cname) + bool remove_claim(const string_view cname) { auto itr = claim_names_.find(cname); if (itr == claim_names_.end()) return false; claim_names_.erase(itr); - payload_.erase(cname.c_str()); + payload_.erase(cname.data()); return true; } @@ -517,6 +524,20 @@ public: // Exposed APIs return header_; } + /** + */ + std::string secret() const + { + return secret_; + } + + /** + */ + void secret(const string_view sv) + { + secret_.assign(sv.data(), sv.length()); + } + /** */ template @@ -524,7 +545,7 @@ public: // Exposed APIs /** */ - jwt_payload& remove_claim(const std::string& name); + jwt_payload& remove_claim(const string_view name); /** */ diff --git a/include/jwt/test/test_jwt_object b/include/jwt/test/test_jwt_object index 855a387..db08c41 100755 Binary files a/include/jwt/test/test_jwt_object and b/include/jwt/test/test_jwt_object differ diff --git a/include/jwt/test/test_jwt_object.cc b/include/jwt/test/test_jwt_object.cc index 493cecd..00e9ecd 100644 --- a/include/jwt/test/test_jwt_object.cc +++ b/include/jwt/test/test_jwt_object.cc @@ -34,6 +34,14 @@ void basic_jwt_object_test() .add_claim("time", 176353563); std::cout << jwt::to_json_str(obj3.payload(), true) << std::endl; + + obj3.remove_claim(std::string{"a"}); + std::cout << obj3.payload() << std::endl; + + obj3.secret("secret"); + obj3.header().algo("hs256"); + + std::cout << obj3.signature() << std::endl; } int main() {