blob: d1b129d2a2571b0c48cdcd84dcc724a06fc9b367 [file] [log] [blame]
// Copyright 2023 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CRYPTOHOME_FLATBUFFER_FILE_H_
#define CRYPTOHOME_FLATBUFFER_FILE_H_
#include <optional>
#include <string>
#include <brillo/secure_blob.h>
#include <libstorage/platform/platform.h>
#include "cryptohome/cryptohome_metrics.h"
#include "cryptohome/error/cryptohome_error.h"
#include "cryptohome/username.h"
namespace cryptohome {
class FlatbufferFile final {
public:
FlatbufferFile(libstorage::Platform* platform, const base::FilePath& path);
FlatbufferFile(const FlatbufferFile&) = delete;
FlatbufferFile& operator=(const FlatbufferFile&) = delete;
~FlatbufferFile();
// StoreFile writes the |buffer| into the file. |buffer| needs to be the
// serialized content. |timer_type| is used to report the time spent on
// storing the file to cryptohome metrics.
CryptohomeStatus StoreFile(const brillo::Blob& buffer,
const TimerType& timer_type) const;
// Returns the contents of the file as a serialized object. |timer_type| is
// used to report the time spent on loading the file to the cryptohome
// metrics.
CryptohomeStatusOr<brillo::Blob> LoadFile(const TimerType& timer_type) const;
private:
libstorage::Platform* const platform_;
base::FilePath const path_;
};
} // namespace cryptohome
#endif // CRYPTOHOME_FLATBUFFER_FILE_H_