Skip to content

Commit

Permalink
Fix compile error with VS2017 (GH #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
noloader committed Sep 7, 2021
1 parent 5cd16a3 commit ac4c98d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
32 changes: 28 additions & 4 deletions pem_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,35 @@ secure_string GetControlFieldData(const secure_string& line)
return secure_string();
}

struct ByteToLower {
byte operator() (byte val) {
return (byte)std::tolower((int)(word32)val);
secure_string ToLower(const secure_string& str)
{
secure_string::const_iterator first = str.begin();
secure_string::const_iterator last = str.end();

secure_string lower;

while (first != last) {
lower.push_back(static_cast<char>(std::tolower(*first)));
first++;
}

return lower;
}

secure_string ToUpper(const secure_string& str)
{
secure_string::const_iterator first = str.begin();
secure_string::const_iterator last = str.end();

secure_string upper;

while (first != last) {
upper.push_back(static_cast<char>(std::toupper(*first)));
first++;
}
};

return upper;
}

// Returns 0 if a match, non-0 otherwise
int CompareNoCase(const secure_string& first, const secure_string& second)
Expand Down
6 changes: 6 additions & 0 deletions pem_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ secure_string GetControlFieldData(const secure_string& line);
// Returns 0 if a match, non-0 otherwise
int CompareNoCase(const secure_string& first, const secure_string& second);

// Returns a string converted to upper-case
secure_string ToLower(const secure_string& str);

// Returns a string converted to lower-case
secure_string ToUpper(const secure_string& str);

// Base64 Encode
void PEM_Base64Encode(BufferedTransformation& source, BufferedTransformation& dest);

Expand Down
13 changes: 4 additions & 9 deletions pem_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ void PEM_CipherForAlgorithm(const EncapsulatedHeader& header,
unsigned int ksize=0, vsize=0;
stream.release();

secure_string alg; alg.reserve(header.m_algorithm.size());
std::transform(header.m_algorithm.begin(), header.m_algorithm.end(),
std::back_inserter(alg), (int(*)(int))std::toupper);
secure_string alg = ToUpper(header.m_algorithm);

if (alg.empty())
goto verify; // verify throws
Expand Down Expand Up @@ -623,8 +621,7 @@ void PEM_ParseOperation(const secure_string& proctype, secure_string& operation)
pos1++;
while (pos1 < proctype.size() && std::isspace(proctype[pos1])) pos1++;

operation = proctype.substr(pos1, secure_string::npos);
std::transform(operation.begin(), operation.end(), operation.begin(), (int(*)(int))std::toupper);
operation = ToUpper(proctype.substr(pos1, secure_string::npos));
}

// The string will be similar to " AES-128-CBC, XXXXXXXXXXXXXXXX"
Expand All @@ -639,8 +636,7 @@ void PEM_ParseAlgorithm(const secure_string& dekinfo, secure_string& algorithm)

while (pos2 > pos1 && std::isspace(dekinfo[pos2])) pos2--;

algorithm = dekinfo.substr(pos1, pos2 - pos1);
std::transform(algorithm.begin(), algorithm.end(), algorithm.begin(), (int(*)(int))std::toupper);
algorithm = ToUpper(dekinfo.substr(pos1, pos2 - pos1));
}

// The string will be similar to " AES-128-CBC, XXXXXXXXXXXXXXXX"
Expand All @@ -653,8 +649,7 @@ void PEM_ParseIV(const secure_string& dekinfo, secure_string& iv)
pos1++;
while (pos1 < dekinfo.size() && std::isspace(dekinfo[pos1])) pos1++;

iv = dekinfo.substr(pos1, secure_string::npos);
std::transform(iv.begin(), iv.end(), iv.begin(), (int(*)(int))std::toupper);
iv = ToUpper(dekinfo.substr(pos1, secure_string::npos));
}

// Read a line of text, until an EOL is encountered. The EOL can be
Expand Down
4 changes: 1 addition & 3 deletions pem_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ void PEM_CipherForAlgorithm(RandomNumberGenerator& rng, std::string algorithm,
unsigned int ksize=0, vsize=0;
stream.release();

secure_string alg; alg.reserve(algorithm.size());
std::transform(algorithm.begin(), algorithm.end(),
std::back_inserter(alg), (int(*)(int))std::toupper);
secure_string alg = ToUpper(secure_string(algorithm));

if (alg.empty())
goto verify; // verify throws
Expand Down

0 comments on commit ac4c98d

Please sign in to comment.