diff options
author | qrort <qrort@yandex-team.com> | 2022-12-02 11:31:25 +0300 |
---|---|---|
committer | qrort <qrort@yandex-team.com> | 2022-12-02 11:31:25 +0300 |
commit | b1f4ffc9c8abff3ba58dc1ec9a9f92d2f0de6806 (patch) | |
tree | 2a23209faf0fea5586a6d4b9cee60d1b318d29fe /library/cpp/tvmauth/src/parser.cpp | |
parent | 559174a9144de40d6bb3997ea4073c82289b4974 (diff) | |
download | ydb-b1f4ffc9c8abff3ba58dc1ec9a9f92d2f0de6806.tar.gz |
remove kikimr/driver DEPENDS
Diffstat (limited to 'library/cpp/tvmauth/src/parser.cpp')
-rw-r--r-- | library/cpp/tvmauth/src/parser.cpp | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/library/cpp/tvmauth/src/parser.cpp b/library/cpp/tvmauth/src/parser.cpp deleted file mode 100644 index 358de58d365..00000000000 --- a/library/cpp/tvmauth/src/parser.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "parser.h" - -#include "utils.h" - -#include <library/cpp/tvmauth/exception.h> - -#include <util/generic/strbuf.h> -#include <util/string/split.h> - -#include <ctime> - -namespace NTvmAuth { - TString TParserTvmKeys::ParseStrV1(TStringBuf str) { - while (str && str.back() == '\n') { - str.Chop(1); - } - - TStringBuf ver = str.NextTok(DELIM); - if (!str || !ver || ver != "1") { - throw TMalformedTvmKeysException() << "Malformed TVM keys"; - } - TString res = NUtils::Base64url2bin(str); - if (res.empty()) { - throw TMalformedTvmKeysException() << "Malformed TVM keys"; - } - return res; - } - - TStringBuf TParserTickets::UserFlag() { - static const char BUF_[] = "user"; - return TStringBuf(BUF_, sizeof(BUF_) - 1); - } - - TStringBuf TParserTickets::ServiceFlag() { - static const char BUF_[] = "serv"; - return TStringBuf(BUF_, sizeof(BUF_) - 1); - } - - TParserTickets::TRes TParserTickets::ParseV3(TStringBuf body, const NRw::TPublicKeys& keys, TStringBuf type) { - TStrRes str = ParseStrV3(body, type); - TRes res(str.Status); - if (str.Status != ETicketStatus::Ok) { - return TRes(str.Status); - } - if (!res.Ticket.ParseFromString(str.Proto)) { - res.Status = ETicketStatus::Malformed; - return res; - } - if (res.Ticket.expirationtime() <= time(nullptr)) { - res.Status = ETicketStatus::Expired; - return res; - } - - auto itKey = keys.find(res.Ticket.keyid()); - if (itKey == keys.end()) { - res.Status = ETicketStatus::MissingKey; - return res; - } - if (!itKey->second.CheckSign(str.ForCheck, str.Sign)) { - res.Status = ETicketStatus::SignBroken; - return res; - } - return res; - } - - TParserTickets::TStrRes TParserTickets::ParseStrV3(TStringBuf body, TStringBuf type) { - TStringBuf forCheck = body; - TStringBuf version = body.NextTok(DELIM); - if (!body || version.size() != 1) { - return {ETicketStatus::Malformed, {}, {}, {}}; - } - if (version != "3") { - return {ETicketStatus::UnsupportedVersion, {}, {}, {}}; - } - - TStringBuf ticketType = body.NextTok(DELIM); - if (ticketType != type) { - return {ETicketStatus::InvalidTicketType, {}, {}, {}}; - } - - TStringBuf proto = body.NextTok(DELIM); - TStringBuf sign = body.NextTok(DELIM); - - if (!proto || !sign || body.size() > 0) { - return {ETicketStatus::Malformed, {}, {}, {}}; - } - - TString protoBin = NUtils::Base64url2bin(proto); - TString signBin = NUtils::Base64url2bin(sign); - - if (!protoBin || !signBin) { - return {ETicketStatus::Malformed, {}, {}, {}}; - } - - return {ETicketStatus::Ok, std::move(protoBin), std::move(signBin), forCheck.Chop(sign.size())}; - } -} |