本文整理汇总了C++中VPackBuilder::toJson方法的典型用法代码示例。如果您正苦于以下问题:C++ VPackBuilder::toJson方法的具体用法?C++ VPackBuilder::toJson怎么用?C++ VPackBuilder::toJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VPackBuilder
的用法示例。
在下文中一共展示了VPackBuilder::toJson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateRawJwt
std::string AuthInfo::generateRawJwt(VPackBuilder const& bodyBuilder) {
VPackBuilder headerBuilder;
{
VPackObjectBuilder h(&headerBuilder);
headerBuilder.add("alg", VPackValue("HS256"));
headerBuilder.add("typ", VPackValue("JWT"));
}
std::string fullMessage(StringUtils::encodeBase64(headerBuilder.toJson()) +
"." +
StringUtils::encodeBase64(bodyBuilder.toJson()));
std::string signature =
sslHMAC(_jwtSecret.c_str(), _jwtSecret.length(), fullMessage.c_str(),
fullMessage.length(), SslInterface::Algorithm::ALGORITHM_SHA256);
return fullMessage + "." + StringUtils::encodeBase64U(signature);
}
示例2: generateSaved
void RestVocbaseBaseHandler::generateSaved(
arangodb::OperationResult const& result, std::string const& collectionName,
TRI_col_type_e type, VPackOptions const* options, bool isMultiple) {
if (result.wasSynchronous) {
createResponse(GeneralResponse::ResponseCode::CREATED);
} else {
createResponse(GeneralResponse::ResponseCode::ACCEPTED);
}
if (isMultiple && !result.countErrorCodes.empty()) {
VPackBuilder errorBuilder;
errorBuilder.openObject();
for (auto const& it : result.countErrorCodes) {
errorBuilder.add(basics::StringUtils::itoa(it.first),
VPackValue(it.second));
}
errorBuilder.close();
_response->setHeaderNC(StaticStrings::ErrorCodes, errorBuilder.toJson());
}
generate20x(result, collectionName, type, options);
}
示例3: generateJwt
std::string RestAuthHandler::generateJwt(std::string const& username, std::string const& password) {
VPackBuilder headerBuilder;
{
VPackObjectBuilder h(&headerBuilder);
headerBuilder.add("alg", VPackValue("HS256"));
headerBuilder.add("typ", VPackValue("JWT"));
}
std::chrono::seconds exp = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch()
) + _validFor;
VPackBuilder bodyBuilder;
{
VPackObjectBuilder p(&bodyBuilder);
bodyBuilder.add("preferred_username", VPackValue(username));
bodyBuilder.add("iss", VPackValue("arangodb"));
bodyBuilder.add("exp", VPackValue(exp.count()));
}
std::string fullMessage(StringUtils::encodeBase64(headerBuilder.toJson()) + "." + StringUtils::encodeBase64(bodyBuilder.toJson()));
std::string signature = sslHMAC(_jwtSecret.c_str(), _jwtSecret.length(), fullMessage.c_str(), fullMessage.length(), SslInterface::Algorithm::ALGORITHM_SHA256);
return fullMessage + "." + StringUtils::encodeBase64U(signature);
}