mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-03 12:32:06 +08:00
qt/api.cc: refactor create_jwt (#21281)
* refactor * cleanup includes old-commit-hash: de56de78c81116c77b0a8ac3c85ed31f16e9aa6f
This commit is contained in:
+11
-19
@@ -1,16 +1,15 @@
|
||||
#include "selfdrive/ui/qt/api.h"
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QRandomGenerator>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
#include "selfdrive/common/params.h"
|
||||
#include "selfdrive/common/util.h"
|
||||
@@ -44,21 +43,14 @@ QByteArray CommaApi::rsa_sign(const QByteArray &data) {
|
||||
return sig;
|
||||
}
|
||||
|
||||
QString CommaApi::create_jwt(const QVector<QPair<QString, QJsonValue>> &payloads, int expiry) {
|
||||
QString CommaApi::create_jwt(const QJsonObject &payloads, int expiry) {
|
||||
QJsonObject header = {{"alg", "RS256"}};
|
||||
|
||||
QString dongle_id = QString::fromStdString(Params().get("DongleId"));
|
||||
|
||||
QJsonObject header;
|
||||
header.insert("alg", "RS256");
|
||||
|
||||
QJsonObject payload;
|
||||
payload.insert("identity", dongle_id);
|
||||
|
||||
auto t = QDateTime::currentSecsSinceEpoch();
|
||||
payload.insert("nbf", t);
|
||||
payload.insert("iat", t);
|
||||
payload.insert("exp", t + expiry);
|
||||
for (auto &load : payloads) {
|
||||
payload.insert(load.first, load.second);
|
||||
QJsonObject payload = {{"identity", dongle_id}, {"nbf", t}, {"iat", t}, {"exp", t + expiry}};
|
||||
for (auto it = payloads.begin(); it != payloads.end(); ++it) {
|
||||
payload.insert(it.key(), it.value());
|
||||
}
|
||||
|
||||
auto b64_opts = QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals;
|
||||
|
||||
+3
-12
@@ -1,25 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QPair>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QWidget>
|
||||
#include <atomic>
|
||||
#include <QTimer>
|
||||
|
||||
class CommaApi : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QByteArray rsa_sign(const QByteArray &data);
|
||||
static QString create_jwt(const QVector<QPair<QString, QJsonValue>> &payloads = {}, int expiry = 3600);
|
||||
static QString create_jwt(const QJsonObject &payloads = {}, int expiry = 3600);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user