aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/src/parser.h
blob: 678e709444664e809ec6bb3ed4e3515df4af5fcd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

#include <library/cpp/tvmauth/src/protos/ticket2.pb.h>
#include <library/cpp/tvmauth/src/rw/keys.h>

#include <library/cpp/tvmauth/ticket_status.h>

#include <util/generic/fwd.h>

#include <string>

namespace NTvmAuth {
    struct TParserTvmKeys {
        static inline const char DELIM = ':';
        static TString ParseStrV1(TStringBuf str);
    };

    struct TParserTickets {
        static const char DELIM = ':';

        static TStringBuf UserFlag();
        static TStringBuf ServiceFlag();

        struct TRes {
            TRes(ETicketStatus status)
                : Status(status)
            {
            }

            ETicketStatus Status;

            ticket2::Ticket Ticket;
        };
        static TRes ParseV3(TStringBuf body, const NRw::TPublicKeys& keys, TStringBuf type);

        // private:
        struct TStrRes {
            const ETicketStatus Status;

            TString Proto;
            TString Sign;

            TStringBuf ForCheck;

            bool operator==(const TStrRes& o) const { // for tests
                return Status == o.Status && Proto == o.Proto && Sign == o.Sign && ForCheck == o.ForCheck;
            }
        };
        static TStrRes ParseStrV3(TStringBuf body, TStringBuf type);
    };
}