aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/client/misc/disk_cache.h
blob: 9e77556f86ec7dddb2a0f7aefcd5a24c7d4790a3 (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
#pragma once

#include <util/datetime/base.h>
#include <util/generic/string.h>

namespace NTvmAuth {
    class ILogger;

    class TDiskReader {
    public:
        TDiskReader(const TString& filename, ILogger* logger = nullptr);

        bool Read();

        const TString& Data() const {
            return Data_;
        }

        TInstant Time() const {
            return Time_;
        }

    public: // for tests
        bool ParseData(TStringBuf buf);

        static TString GetHash(TStringBuf data);
        static time_t GetTimestamp(TStringBuf data);

    private:
        TString Filename_;
        ILogger* Logger_;
        TInstant Time_;
        TString Data_;
    };

    class TDiskWriter {
    public:
        TDiskWriter(const TString& filename, ILogger* logger = nullptr);

        bool Write(TStringBuf data, TInstant now = TInstant::Now());

    public: // for tests
        static TString PrepareData(TInstant time, TStringBuf data);
        static TString WriteTimestamp(time_t time);

    private:
        TString Filename_;
        ILogger* Logger_;
    };
}