diff --git a/openframe/openframe_token_extractor.cpp b/openframe/openframe_token_extractor.cpp index 31e2987b1ae..49d5aa64909 100644 --- a/openframe/openframe_token_extractor.cpp +++ b/openframe/openframe_token_extractor.cpp @@ -1,23 +1,34 @@ +/** + * Copyright (c) 2014-present, The osquery authors + * + * This source code is licensed as defined by the LICENSE file found in the + * root directory of this source tree. + * + * SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only) + */ + #include "openframe_token_extractor.h" #include -#include + +namespace osquery { OpenframeTokenExtractor::OpenframeTokenExtractor(std::shared_ptr encryption_service, const std::string& token_file_path) : encryption_service_(encryption_service), token_file_path_(token_file_path) { +} + +Status OpenframeTokenExtractor::extractToken(std::string& token) { if (!encryption_service_) { - throw std::runtime_error("Encryption service cannot be null"); + return Status::failure("Encryption service cannot be null"); } if (token_file_path_.empty()) { - throw std::runtime_error("Token file path cannot be empty"); + return Status::failure("Token file path cannot be empty"); } -} -std::string OpenframeTokenExtractor::extractToken() { // Open the token file std::ifstream token_file(token_file_path_); if (!token_file.is_open()) { - throw std::runtime_error("Failed to open token file at: " + token_file_path_); + return Status::failure("Failed to open token file at: " + token_file_path_); } // Read the encrypted token @@ -26,13 +37,17 @@ std::string OpenframeTokenExtractor::extractToken() { token_file.close(); if (encrypted_token.empty()) { - throw std::runtime_error("Token file is empty"); + return Status::failure("Token file is empty"); } try { // Decrypt the token using the encryption service - return encryption_service_->decrypt(encrypted_token); + token = encryption_service_->decrypt(encrypted_token); } catch (const std::exception& e) { - throw std::runtime_error("Failed to decrypt token: " + std::string(e.what())); + return Status::failure("Failed to decrypt token: " + std::string(e.what())); } -} \ No newline at end of file + + return Status::success(); +} + +} // namespace osquery