Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

MAID-523 Replacing boost::regex with std::regex #76

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ target_link_libraries(maidsafe_common
${BoostChronoLibs}
${BoostDateTimeLibs}
${BoostFilesystemLibs}
${BoostLocaleLibs}
${BoostRegexLibs}
${BoostSystemLibs}
${BoostThreadLibs}
${BoostProgramOptionsLibs}
Expand Down
18 changes: 9 additions & 9 deletions include/maidsafe/common/authentication/detail/secure_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <map>
#include <functional>

#include "boost/regex.hpp"
#include <regex>

// Include this first to avoid having to wrap the cryptopp includes in a pragma to disable warnings
#include "maidsafe/common/crypto.h" // NOLINT
Expand Down Expand Up @@ -111,7 +111,7 @@ class SecureInputString {

bool IsInitialised() const;
bool IsFinalised() const;
bool IsValid(const boost::regex& regex) const;
bool IsValid(const std::regex& regex) const;

template <typename HashType>
SecureString::Hash Hash() const;
Expand All @@ -125,8 +125,8 @@ class SecureInputString {
SafeString Encrypt(const StringType& decrypted_chars) const;
SafeString Encrypt(const char& decrypted_char) const;
SafeString Decrypt(const SafeString& encrypted_char) const;
bool ValidateEncryptedChars(const boost::regex& regex) const;
bool ValidateSecureString(const boost::regex& regex) const;
bool ValidateEncryptedChars(const std::regex& regex) const;
bool ValidateSecureString(const std::regex& regex) const;

std::map<size_type, SafeString> encrypted_chars_;
SafeString phrase_;
Expand Down Expand Up @@ -240,7 +240,7 @@ bool SecureInputString<Predicate, Size, Tag>::IsFinalised() const {
}

template <typename Predicate, SecureString::size_type Size, typename Tag>
bool SecureInputString<Predicate, Size, Tag>::IsValid(const boost::regex& regex) const {
bool SecureInputString<Predicate, Size, Tag>::IsValid(const std::regex& regex) const {
return IsFinalised() ? ValidateSecureString(regex) : ValidateEncryptedChars(regex);
}

Expand Down Expand Up @@ -312,15 +312,15 @@ SafeString SecureInputString<Predicate, Size, Tag>::Decrypt(

template <typename Predicate, SecureString::size_type Size, typename Tag>
bool SecureInputString<Predicate, Size, Tag>::ValidateEncryptedChars(
const boost::regex& regex) const {
const std::regex& regex) const {
if (!Predicate()(encrypted_chars_.size(), Size))
return false;
uint32_t counter(0);
for (auto& encrypted_char : encrypted_chars_) {
if (encrypted_char.first != counter)
return false;
SafeString decrypted_char(Decrypt(encrypted_char.second));
if (!boost::regex_search(decrypted_char, regex))
if (!std::regex_search(decrypted_char, regex))
return false;
++counter;
}
Expand All @@ -329,13 +329,13 @@ bool SecureInputString<Predicate, Size, Tag>::ValidateEncryptedChars(

template <typename Predicate, SecureString::size_type Size, typename Tag>
bool SecureInputString<Predicate, Size, Tag>::ValidateSecureString(
const boost::regex& regex) const {
const std::regex& regex) const {
SafeString decrypted_string(string());
size_type decrypted_string_size(decrypted_string.size());
if (!Predicate()(decrypted_string_size, Size))
return false;
for (size_type i = 0; i != decrypted_string_size; ++i) {
if (!boost::regex_search(SafeString(1, decrypted_string[i]), regex))
if (!std::regex_search(SafeString(1, decrypted_string[i]), regex))
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "maidsafe/common/authentication/detail/secure_string.h"

#include "boost/regex.hpp"
#include <regex>

#include "maidsafe/common/error.h"
#include "maidsafe/common/log.h"
Expand Down Expand Up @@ -296,7 +296,7 @@ TEST(SecureStringTest, BEH_CheckPasswordIsValidForAllChars) {
for (size_t i(0); i != 23; ++i)
EXPECT_NO_THROW(password.Insert(i, static_cast<char>(RandomInt32())));

ASSERT_TRUE(password.IsValid(boost::regex(".")));
ASSERT_TRUE(password.IsValid(std::regex(".")));

EXPECT_NO_THROW(password.Finalise());
}
Expand Down Expand Up @@ -338,13 +338,13 @@ TEST(SecureStringTest, BEH_InsertInvalidPinValue) {
EXPECT_NO_THROW(pin.Finalise());

ASSERT_EQ(SafeString("a123"), pin.string());
EXPECT_TRUE(pin.IsValid(boost::regex(".")));
EXPECT_TRUE(pin.IsValid(std::regex(".")));
EXPECT_THROW(pin.Value(), std::exception);

EXPECT_NO_THROW(pin.Remove(0, 1));
EXPECT_NO_THROW(pin.Insert(0, '0'));
EXPECT_NO_THROW(pin.Finalise());
EXPECT_TRUE(pin.IsValid(boost::regex(".")));
EXPECT_TRUE(pin.IsValid(std::regex(".")));

EXPECT_NO_THROW(pin.Finalise());
ASSERT_EQ(123, pin.Value());
Expand Down