Skip to content

Commit

Permalink
Remove StringRef
Browse files Browse the repository at this point in the history
  • Loading branch information
netheril96 committed Feb 28, 2024
1 parent c4dcaae commit b1ae3a6
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 203 deletions.
16 changes: 8 additions & 8 deletions sources/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void fix(const std::string& basedir, operations::FileSystemContext* fs)
}

void hmac_sha256(const securefs::key_type& base_key,
StringRef maybe_key_file_path,
const std::string& maybe_key_file_path,
securefs::key_type& out_key)
{
if (maybe_key_file_path.empty())
Expand All @@ -309,7 +309,7 @@ void hmac_sha256(const securefs::key_type& base_key,
}

Json::Value generate_config(const std::string& pbkdf_algorithm,
StringRef maybe_key_file_path,
const std::string& maybe_key_file_path,
const securefs::key_type& salt,
const void* password,
size_t pass_len,
Expand Down Expand Up @@ -485,7 +485,7 @@ void compute_password_derived_key(const Json::Value& config,
}

FSConfig parse_config(const Json::Value& config,
StringRef maybe_key_file_path,
const std::string& maybe_key_file_path,
const void* password,
size_t pass_len)
{
Expand Down Expand Up @@ -584,7 +584,7 @@ std::shared_ptr<FileStream> CommandBase::open_config_stream(const std::string& p
FSConfig CommandBase::read_config(FileStream* stream,
const void* password,
size_t pass_len,
StringRef maybe_key_file_path)
const std::string& maybe_key_file_path)
{
FSConfig result;

Expand Down Expand Up @@ -621,7 +621,7 @@ static void copy_key(const CryptoPP::AlignedSecByteBlock& in_key, optional<key_t
}

void CommandBase::write_config(FileStream* stream,
StringRef maybe_key_file_path,
const std::string& maybe_key_file_path,
const std::string& pbdkf_algorithm,
const FSConfig& config,
const void* password,
Expand Down Expand Up @@ -904,7 +904,7 @@ class ChangePasswordCommand : public _DataDirCommandBase
"",
"string"};

static void assign(StringRef value, CryptoPP::AlignedSecByteBlock& output)
static void assign(absl::string_view value, CryptoPP::AlignedSecByteBlock& output)
{
output.Assign(reinterpret_cast<const byte*>(value.data()), value.size());
}
Expand Down Expand Up @@ -1064,11 +1064,11 @@ class MountCommand : public _SinglePasswordCommandBase
}
#ifdef WIN32
static bool is_letter(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); }
static bool is_drive_mount(StringRef mount_point)
static bool is_drive_mount(absl::string_view mount_point)
{
return mount_point.size() == 2 && is_letter(mount_point[0]) && mount_point[1] == ':';
}
static bool is_network_mount(StringRef mount_point)
static bool is_network_mount(absl::string_view mount_point)
{
return mount_point.starts_with("\\\\") && !mount_point.starts_with("\\\\?\\");
}
Expand Down
8 changes: 5 additions & 3 deletions sources/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class CommandBase

protected:
static std::shared_ptr<FileStream> open_config_stream(const std::string& full_path, int flags);
static FSConfig
read_config(FileStream*, const void* password, size_t pass_len, StringRef maybe_key_file_path);
static FSConfig read_config(FileStream*,
const void* password,
size_t pass_len,
const std::string& maybe_key_file_path);
static void write_config(FileStream*,
StringRef maybe_key_file_path,
const std::string& maybe_key_file_path,
const std::string& pbdkf_algorithm,
const FSConfig&,
const void* password,
Expand Down
49 changes: 26 additions & 23 deletions sources/lite_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace lite
return absl::StrFormat("Invalid filename \"%s\"", m_filename);
}

std::string legacy_encrypt_path(AES_SIV& encryptor, StringRef path)
std::string legacy_encrypt_path(AES_SIV& encryptor, absl::string_view path)
{
byte buffer[2032];
std::string result;
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace lite
return result;
}

std::string legacy_decrypt_path(AES_SIV& decryptor, StringRef path)
std::string legacy_decrypt_path(AES_SIV& decryptor, absl::string_view path)
{
byte string_buffer[2032];
std::string result, decoded_part;
Expand Down Expand Up @@ -117,7 +117,7 @@ namespace lite
string_buffer,
&decoded_part[0]);
if (!success)
throw InvalidFilenameException(path.to_string());
throw InvalidFilenameException(std::string(path));
result.append((const char*)string_buffer,
decoded_part.size() - AES_SIV::IV_SIZE);
}
Expand All @@ -129,7 +129,7 @@ namespace lite
return result;
}

std::string FileSystem::translate_path(StringRef path, bool preserve_leading_slash)
std::string FileSystem::translate_path(absl::string_view path, bool preserve_leading_slash)
{
if (path.empty())
{
Expand All @@ -149,12 +149,12 @@ namespace lite
else
{
std::string str = !m_name_encryptor
? path.to_string()
? std::string(path)
: lite::legacy_encrypt_path(*m_name_encryptor,
transform(path,
m_flags & kOptionCaseFoldFileName,
m_flags & kOptionNFCFileName)
.get());
.view());
if (!preserve_leading_slash && !str.empty() && str[0] == '/')
{
str.erase(str.begin());
Expand All @@ -164,7 +164,7 @@ namespace lite
}
}

AutoClosedFile FileSystem::open(StringRef path, int flags, fuse_mode_t mode)
AutoClosedFile FileSystem::open(absl::string_view path, int flags, fuse_mode_t mode)
{
if (flags & O_APPEND)
{
Expand Down Expand Up @@ -199,7 +199,7 @@ namespace lite
return fp;
}

bool FileSystem::stat(StringRef path, struct fuse_stat* buf)
bool FileSystem::stat(absl::string_view path, struct fuse_stat* buf)
{
auto enc_path = translate_path(path, false);
if (!m_root->stat(enc_path, buf))
Expand Down Expand Up @@ -261,7 +261,7 @@ namespace lite
{
ERROR_LOG("Encountered exception %s when opening file %s for read: %s",
get_type_name(e).get(),
path.c_str(),
path,
e.what());
}
}
Expand All @@ -273,39 +273,39 @@ namespace lite
return true;
}

void FileSystem::mkdir(StringRef path, fuse_mode_t mode)
void FileSystem::mkdir(absl::string_view path, fuse_mode_t mode)
{
m_root->mkdir(translate_path(path, false), mode);
}

void FileSystem::rmdir(StringRef path)
void FileSystem::rmdir(absl::string_view path)
{
m_root->remove_directory(translate_path(path, false));
}

void FileSystem::rename(StringRef from, StringRef to)
void FileSystem::rename(absl::string_view from, absl::string_view to)
{
m_root->rename(translate_path(from, false), translate_path(to, false));
}

void FileSystem::chmod(StringRef path, fuse_mode_t mode)
void FileSystem::chmod(absl::string_view path, fuse_mode_t mode)
{
if (!(mode & S_IRUSR))
{
WARN_LOG("Change the mode of file %s to 0%o which denies user read access. "
"Mysterious bugs will occur.",
path.c_str(),
path,
static_cast<unsigned>(mode));
}
m_root->chmod(translate_path(path, false), mode);
}

void FileSystem::chown(StringRef path, fuse_uid_t uid, fuse_gid_t gid)
void FileSystem::chown(absl::string_view path, fuse_uid_t uid, fuse_gid_t gid)
{
m_root->chown(translate_path(path, false), uid, gid);
}

size_t FileSystem::readlink(StringRef path, char* buf, size_t size)
size_t FileSystem::readlink(absl::string_view path, char* buf, size_t size)
{
if (size <= 0)
return size;
Expand All @@ -323,20 +323,23 @@ namespace lite
return copy_size;
}

void FileSystem::symlink(StringRef to, StringRef from)
void FileSystem::symlink(absl::string_view to, absl::string_view from)
{
auto eto = translate_path(to, true), efrom = translate_path(from, false);
m_root->symlink(eto, efrom);
}

void FileSystem::utimens(StringRef path, const fuse_timespec* ts)
void FileSystem::utimens(absl::string_view path, const fuse_timespec* ts)
{
m_root->utimens(translate_path(path, false), ts);
}

void FileSystem::unlink(StringRef path) { m_root->remove_file(translate_path(path, false)); }
void FileSystem::unlink(absl::string_view path)
{
m_root->remove_file(translate_path(path, false));
}

void FileSystem::link(StringRef src, StringRef dest)
void FileSystem::link(absl::string_view src, absl::string_view dest)
{
m_root->link(translate_path(src, false), translate_path(dest, false));
}
Expand Down Expand Up @@ -369,7 +372,7 @@ namespace lite
{
}

StringRef path() const override { return m_path; }
absl::string_view path() const override { return m_path; }

void rewind() override ABSL_EXCLUSIVE_LOCKS_REQUIRED(*this)
{
Expand Down Expand Up @@ -448,12 +451,12 @@ namespace lite
}
};

std::unique_ptr<Directory> FileSystem::opendir(StringRef path)
std::unique_ptr<Directory> FileSystem::opendir(absl::string_view path)
{
if (path.empty())
throwVFSException(EINVAL);
return securefs::make_unique<LiteDirectory>(
path.to_string(),
std::string(path),
m_root->create_traverser(translate_path(path, false)),
this->m_name_encryptor,
m_block_size,
Expand Down
42 changes: 21 additions & 21 deletions sources/lite_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace lite
Directory* as_dir() noexcept { return this; }

// Obtains the (virtual) path of the directory.
virtual StringRef path() const = 0;
virtual absl::string_view path() const = 0;

// Redeclare the methods in `DirectoryTraverser` to add thread safe annotations.
virtual bool next(std::string* name, struct fuse_stat* st)
Expand Down Expand Up @@ -130,8 +130,8 @@ namespace lite

typedef std::unique_ptr<File> AutoClosedFile;

std::string legacy_encrypt_path(AES_SIV& encryptor, StringRef path);
std::string legacy_decrypt_path(AES_SIV& decryptor, StringRef path);
std::string legacy_encrypt_path(AES_SIV& encryptor, absl::string_view path);
std::string legacy_decrypt_path(AES_SIV& decryptor, absl::string_view path);

class InvalidFilenameException : public VerificationException
{
Expand Down Expand Up @@ -161,13 +161,13 @@ namespace lite
unsigned m_flags;

private:
std::string translate_path(StringRef path, bool preserve_leading_slash);
std::string translate_path(absl::string_view path, bool preserve_leading_slash);

static std::string legacy_encrypt_symlink(StringRef path);
static std::string legacy_decrypt_symlink(StringRef path);
static std::string legacy_encrypt_symlink(absl::string_view path);
static std::string legacy_decrypt_symlink(absl::string_view path);

static std::string new_encrypt_symlink(StringRef path);
static std::string new_decrypt_symlink(StringRef path);
static std::string new_encrypt_symlink(absl::string_view path);
static std::string new_decrypt_symlink(absl::string_view path);

public:
FileSystem(std::shared_ptr<const securefs::OSService> root,
Expand All @@ -182,20 +182,20 @@ namespace lite

~FileSystem();

AutoClosedFile open(StringRef path, int flags, fuse_mode_t mode);
bool stat(StringRef path, struct fuse_stat* buf);
void mkdir(StringRef path, fuse_mode_t mode);
void rmdir(StringRef path);
void chmod(StringRef path, fuse_mode_t mode);
void chown(StringRef path, fuse_uid_t uid, fuse_gid_t gid);
void rename(StringRef from, StringRef to);
void unlink(StringRef path);
void symlink(StringRef to, StringRef from);
void link(StringRef src, StringRef dest);
size_t readlink(StringRef path, char* buf, size_t size);
void utimens(StringRef path, const fuse_timespec tm[2]);
AutoClosedFile open(absl::string_view path, int flags, fuse_mode_t mode);
bool stat(absl::string_view path, struct fuse_stat* buf);
void mkdir(absl::string_view path, fuse_mode_t mode);
void rmdir(absl::string_view path);
void chmod(absl::string_view path, fuse_mode_t mode);
void chown(absl::string_view path, fuse_uid_t uid, fuse_gid_t gid);
void rename(absl::string_view from, absl::string_view to);
void unlink(absl::string_view path);
void symlink(absl::string_view to, absl::string_view from);
void link(absl::string_view src, absl::string_view dest);
size_t readlink(absl::string_view path, char* buf, size_t size);
void utimens(absl::string_view path, const fuse_timespec tm[2]);
void statvfs(struct fuse_statvfs* buf);
std::unique_ptr<Directory> opendir(StringRef path);
std::unique_ptr<Directory> opendir(absl::string_view path);

bool has_padding() const noexcept { return m_max_padding_size > 0; }
bool skip_dot_dot() const noexcept { return m_flags & kOptionSkipDotDot; }
Expand Down
2 changes: 1 addition & 1 deletion sources/lite_long_name_lookup_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ std::string encrypt_long_name_component(AES_SIV& encryptor, absl::string_view lo
return absl::StrCat("_", hexify(buffer), "_");
}

LongNameLookupTable::LongNameLookupTable(StringRef filename, bool readonly)
LongNameLookupTable::LongNameLookupTable(const std::string& filename, bool readonly)
{
db_ = SQLiteDB(
filename.c_str(),
Expand Down
2 changes: 1 addition & 1 deletion sources/lite_long_name_lookup_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace securefs
class ABSL_LOCKABLE LongNameLookupTable
{
public:
LongNameLookupTable(StringRef filename, bool readonly);
LongNameLookupTable(const std::string& filename, bool readonly);
~LongNameLookupTable();

std::vector<unsigned char> lookup(absl::Span<const unsigned char> encrypted_hash)
Expand Down

0 comments on commit b1ae3a6

Please sign in to comment.