diff options
author | Paul Crowley <paulcrowley@google.com> | 2019-10-25 10:19:10 -0700 |
---|---|---|
committer | Paul Crowley <paulcrowley@google.com> | 2019-10-28 14:37:45 -0700 |
commit | be2aeea99ec04ea60c61e568ddf477f852ce95ff (patch) | |
tree | 8059f6ca26efcaf5052ed4c8eabd8840a701ef42 /libfscrypt | |
parent | 5e2fbc4cf572f1e0795602d9e96cef9839a5cc18 (diff) | |
download | extras-be2aeea99ec04ea60c61e568ddf477f852ce95ff.tar.gz |
libfscrypt: No need for parts-parsing any more, integrate code.
Bug: 143307095
Test: atest libfscrypt_unit_test
Change-Id: Ieb72dc88c227128ecadc44096a2266fe2af0d20b
Diffstat (limited to 'libfscrypt')
-rw-r--r-- | libfscrypt/fscrypt.cpp | 58 | ||||
-rw-r--r-- | libfscrypt/include/fscrypt/fscrypt.h | 5 |
2 files changed, 22 insertions, 41 deletions
diff --git a/libfscrypt/fscrypt.cpp b/libfscrypt/fscrypt.cpp index c29cf1e8..b73f1bc8 100644 --- a/libfscrypt/fscrypt.cpp +++ b/libfscrypt/fscrypt.cpp @@ -212,46 +212,32 @@ bool ParseOptions(const std::string& options_string, EncryptionOptions* options) if (parts.size() < 1 || parts.size() > 3) { return false; } - if (parts.size() < 2) { - if (parts[0] == "adiantum") { - parts.emplace_back("adiantum"); - } else { - parts.emplace_back("aes-256-cts"); - } - } - if (parts.size() < 3) { - parts.emplace_back("v1"); - } - - return ParseOptionsParts(parts[0], parts[1], parts[2], options); -} - -bool ParseOptionsParts(const std::string& contents_mode, const std::string& filenames_mode, - const std::string& flags, EncryptionOptions* options) { - int policy_version; - if (flags == "v1") { - policy_version = 1; - } else if (flags == "v2") { - policy_version = 2; - } else { - LOG(ERROR) << "Unknown flag: " << flags; + if (!LookupModeByName(contents_modes, parts[0], &options->contents_mode)) { + LOG(ERROR) << "Invalid file contents encryption mode: " << parts[0]; return false; } - return ParseOptionsParts(contents_mode, filenames_mode, policy_version, options); -} - -bool ParseOptionsParts(const std::string& contents_mode, const std::string& filenames_mode, - int policy_version, EncryptionOptions* options) { - if (!LookupModeByName(contents_modes, contents_mode, &options->contents_mode)) { - LOG(ERROR) << "Invalid file contents encryption mode: " << contents_mode; - return false; + if (parts.size() >= 2) { + if (!LookupModeByName(filenames_modes, parts[1], &options->filenames_mode)) { + LOG(ERROR) << "Invalid file names encryption mode: " << parts[1]; + return false; + } + } else if (options->contents_mode == FS_ENCRYPTION_MODE_ADIANTUM) { + options->filenames_mode = FS_ENCRYPTION_MODE_ADIANTUM; + } else { + options->filenames_mode = FS_ENCRYPTION_MODE_AES_256_CTS; } - if (!LookupModeByName(filenames_modes, filenames_mode, &options->filenames_mode)) { - LOG(ERROR) << "Invalid file names encryption mode: " << filenames_mode; - return false; + if (parts.size() >= 3) { + if (parts[2] == "v1") { + options->version = 1; + } else if (parts[2] == "v2") { + options->version = 2; + } else { + LOG(ERROR) << "Unknown flag: " << parts[2]; + return false; + } + } else { + options->version = 1; } - - options->version = policy_version; return true; } diff --git a/libfscrypt/include/fscrypt/fscrypt.h b/libfscrypt/include/fscrypt/fscrypt.h index ccd716f2..47fedb5c 100644 --- a/libfscrypt/include/fscrypt/fscrypt.h +++ b/libfscrypt/include/fscrypt/fscrypt.h @@ -48,11 +48,6 @@ bool OptionsToString(const EncryptionOptions& options, std::string* options_stri bool ParseOptions(const std::string& options_string, EncryptionOptions* options); -bool ParseOptionsParts(const std::string& contents_mode, const std::string& filenames_mode, - const std::string& flags, EncryptionOptions* options); - -bool ParseOptionsParts(const std::string& contents_mode, const std::string& filenames_mode, - int policy_version, EncryptionOptions* options); bool EnsurePolicy(const EncryptionPolicy& policy, const std::string& directory); } // namespace fscrypt |