Skip to content

Commit

Permalink
Migrate enum to enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jszczerbinski committed Oct 29, 2024
1 parent 7428cad commit 3e422e3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 111 deletions.
8 changes: 4 additions & 4 deletions cpp/platform/SecureStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace sf
const std::string& token)
{
SecureStorageImpl secStorage;
if (secStorage.storeToken(host, username, credType, token) != SUCCESS)
if (secStorage.storeToken(host, username, credType, token) != SecureStorageStatus::Success)
{
log_error("Failed to store secure token%s", "");
return false;
Expand All @@ -33,7 +33,7 @@ namespace sf
{
SecureStorageImpl secStorage;
std::string result;
if (secStorage.retrieveToken(host, username, credType, result) != SUCCESS)
if (secStorage.retrieveToken(host, username, credType, result) != SecureStorageStatus::Success)
{
log_error("Failed to retrieve secure token%s", "");
return {};
Expand All @@ -49,7 +49,7 @@ namespace sf
const std::string& token)
{
SecureStorageImpl secStorage;
if ( secStorage.updateToken(host, username, credType, token) != SUCCESS)
if ( secStorage.updateToken(host, username, credType, token) != SecureStorageStatus::Success)
{
log_error("Failed to update secure token%s", "");
return false;
Expand All @@ -64,7 +64,7 @@ namespace sf
const std::string& credType)
{
SecureStorageImpl secStorage;
if ( secStorage.removeToken(host, username, credType) != SUCCESS)
if ( secStorage.removeToken(host, username, credType) != SecureStorageStatus::Success)
{
log_error("Failed to remove secure token%s", "");
return false;
Expand Down
24 changes: 12 additions & 12 deletions cpp/platform/SecureStorageApple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace sf
return ss.str();
}

SECURE_STORAGE_STATUS SecureStorageImpl::storeToken(const std::string& host,
SecureStorageStatus SecureStorageImpl::storeToken(const std::string& host,
const std::string& username,
const std::string& credType,
const std::string& cred)
Expand Down Expand Up @@ -78,14 +78,14 @@ namespace sf
if (result != errSecSuccess)
{
CXX_LOG_ERROR("Failed to store secure token");
return ERROR;
return SecureStorageStatus::Error;
}

CXX_LOG_DEBUG("Successfully stored secure token");
return SUCCESS;
return SecureStorageStatus::Success;
}

SECURE_STORAGE_STATUS SecureStorageImpl::retrieveToken(const std::string& host,
SecureStorageStatus SecureStorageImpl::retrieveToken(const std::string& host,
const std::string& username,
const std::string& credType,
std::string& cred)
Expand Down Expand Up @@ -117,24 +117,24 @@ namespace sf
{
cred = "";
CXX_LOG_ERROR("Failed to retrieve secure token - %s", "Token Not Found");
return NOT_FOUND;
return SecureStorageStatus::NotFound;
}

if (status != errSecSuccess)
{
cred = "";
CXX_LOG_ERROR("Failed to retrieve secure token");
return ERROR;
return SecureStorageStatus::Error;
}

CXX_LOG_DEBUG("Successfully retrieved token");

auto val = reinterpret_cast<CFDataRef>(CFDictionaryGetValue(result, kSecValueData));
cred = std::string(reinterpret_cast<const char*>(CFDataGetBytePtr(val)), CFDataGetLength(val));
return SUCCESS;
return SecureStorageStatus::Success;
}

SECURE_STORAGE_STATUS SecureStorageImpl::updateToken(const std::string& host,
SecureStorageStatus SecureStorageImpl::updateToken(const std::string& host,
const std::string& username,
const std::string& credType,
const std::string& token)
Expand All @@ -161,13 +161,13 @@ namespace sf
if (result != errSecSuccess && result != errSecItemNotFound)
{
CXX_LOG_ERROR("Failed to update secure token");
return ERROR;
return SecureStorageStatus::Error;
}

return storeToken(host, username, credType, token);
}

SECURE_STORAGE_STATUS SecureStorageImpl::removeToken(const std::string& host,
SecureStorageStatus SecureStorageImpl::removeToken(const std::string& host,
const std::string& username,
const std::string& credType)
{
Expand All @@ -192,11 +192,11 @@ namespace sf
if (result != errSecSuccess && result != errSecItemNotFound)
{
CXX_LOG_ERROR("Failed to remove secure token");
return ERROR;
return SecureStorageStatus::Error;
}

CXX_LOG_DEBUG("Successfully removed secure token");
return SUCCESS;
return SecureStorageStatus::Success;
}
}

Expand Down
20 changes: 10 additions & 10 deletions cpp/platform/SecureStorageImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

#include <string>

typedef enum
enum class SecureStorageStatus
{
NOT_FOUND,
ERROR,
SUCCESS,
UNSUPPORTED
}SECURE_STORAGE_STATUS;
NotFound,
Error,
Success,
Unsupported
};

namespace sf
{
Expand Down Expand Up @@ -42,7 +42,7 @@ namespace sf
*
* @return ERROR / SUCCESS
*/
SECURE_STORAGE_STATUS storeToken(const std::string& host,
SecureStorageStatus storeToken(const std::string& host,
const std::string& username,
const std::string& credType,
const std::string& cred);
Expand All @@ -62,7 +62,7 @@ namespace sf
* @param credLen - on return, length of the credential retrieved
* @return NOT_FOUND, ERROR, SUCCESS
*/
SECURE_STORAGE_STATUS retrieveToken(const std::string& host,
SecureStorageStatus retrieveToken(const std::string& host,
const std::string& username,
const std::string& credType,
std::string& cred);
Expand All @@ -80,7 +80,7 @@ namespace sf
* @param cred - credential to be stored in the keychain.
* @return ERROR / SUCCESS
*/
SECURE_STORAGE_STATUS updateToken(const std::string& host,
SecureStorageStatus updateToken(const std::string& host,
const std::string& username,
const std::string& credType,
const std::string& cred);
Expand All @@ -98,7 +98,7 @@ namespace sf
*
* @return ERROR / SUCCESS
*/
SECURE_STORAGE_STATUS removeToken(const std::string& host,
SecureStorageStatus removeToken(const std::string& host,
const std::string& username,
const std::string& credType);
};
Expand Down
16 changes: 8 additions & 8 deletions cpp/platform/SecureStorageUnSup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@
namespace sf
{

SECURE_STORAGE_STATUS SecureStorageImpl::storeToken(const std::string& host,
SecureStorageStatus SecureStorageImpl::storeToken(const std::string& host,
const std::string& username,
const std::string& credType,
const std::string& token)
{
return UNSUPPORTED;
return SecureStorageStatus::Unsupported;
}

SECURE_STORAGE_STATUS SecureStorageImpl::retrieveToken(const std::string& host,
SecureStorageStatus SecureStorageImpl::retrieveToken(const std::string& host,
const std::string& username,
const std::string& credType,
std::string& token)
{
return UNSUPPORTED;
return SecureStorageStatus::Unsupported;
}

SECURE_STORAGE_STATUS SecureStorageImpl::updateToken(const std::string& host,
SecureStorageStatus SecureStorageImpl::updateToken(const std::string& host,
const std::string& username,
const std::string& credType,
const std::string& token)
{
return UNSUPPORTED;
return SecureStorageStatus::Unsupported;
}

SECURE_STORAGE_STATUS SecureStorageImpl::removeToken(const std::string& host,
SecureStorageStatus SecureStorageImpl::removeToken(const std::string& host,
const std::string& username,
const std::string& credType)
{
return UNSUPPORTED;
return SecureStorageStatus::Unsupported;
}
}

Expand Down
Loading

0 comments on commit 3e422e3

Please sign in to comment.