MCPcopy Create free account
hub / github.com/arun11299/cpp-jwt / sign

Method sign

include/jwt/algorithm.hpp:351–372  ·  view source on GitHub ↗

* Signs the input using the HMAC algorithm using the * provided key. * * Arguments: * @key : The secret/key to use for the signing. * Cannot be empty string. * @data : The data to be signed. * * Exceptions: * Any allocation failure will result in jwt::MemoryAllocationException * being thrown. */

Source from the content-addressed store, hash-verified

349 * being thrown.
350 */
351 static sign_result_t sign(const jwt::string_view key, const jwt::string_view data)
352 {
353 std::string sign;
354 sign.resize(EVP_MAX_MD_SIZE);
355 std::error_code ec{};
356
357 uint32_t len = 0;
358
359 unsigned char* res = HMAC(Hasher{}(),
360 key.data(),
361 static_cast<int>(key.length()),
362 reinterpret_cast<const unsigned char*>(data.data()),
363 data.length(),
364 reinterpret_cast<unsigned char*>(&sign[0]),
365 &len);
366 if (!res) {
367 ec = AlgorithmErrc::SigningErr;
368 }
369
370 sign.resize(len);
371 return { std::move(sign), ec };
372 }
373
374 /**
375 * Verifies the JWT string against the signature using

Callers

nothing calls this directly

Calls 2

dataMethod · 0.80
lengthMethod · 0.80

Tested by

no test coverage detected