Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypto++ byte change at Crypto++ 6.0 #2

Closed
noloader opened this issue Nov 27, 2017 · 3 comments
Closed

Crypto++ byte change at Crypto++ 6.0 #2

noloader opened this issue Nov 27, 2017 · 3 comments
Labels

Comments

@noloader
Copy link

noloader commented Nov 27, 2017

This is based on feedback from Compiling bfx-cpp-api - Byte datatype undeclared on Stack Overflow. When using the current Crypto++ Master and soon to be Crypto++ 6.0, we moved our byte definition into the CryptoPP namespace.

The move was necessary because of C++17's std::byte and Microsoft's byte which is also in the global namespace. C++17 ensured something was going to break, so we stepped out of the way of the train and did what we were supposed to do years ago (namely, placed byte in our namespace). Now Microsoft SDKs are the one that's going to break things when it collides with C++17. Also see Crypto++ Issue 442 on the Crypto++ bug tracker and std::byte in the Crypto++ wiki.

The short of it for BFX-API is, you can do the following if you want to preserve old behavior. But keep in mind this is going to move the problem from Crypto++ to BFX-API:

// CRYPTOPP_NO_GLOBAL_BYTE signals byte is at CryptoPP::byte
#if defined(CRYPTOPP_NO_GLOBAL_BYTE)
  typedef unsigned char byte;
#endif

You could also perform the following which produces a similar effect:

// CRYPTOPP_NO_GLOBAL_BYTE signals byte is at CryptoPP::byte
#if defined(CRYPTOPP_NO_GLOBAL_BYTE)
  using CryptoPP::byte;
#endif

When we moved the Crypto++ byte to CryptoPP::byte we added the define CRYPTOPP_NO_GLOBAL_BYTE so downstream had a signal for remediations like above.


Here is a test using example.cpp from BFX-API. In the test, Crypto++ and BFX are side-by-side, so there is a bfx/ folder and a cryptopp/ folder.

$ g++ BitfinexAPI.cpp example.cpp -I ../ ../cryptopp/libcryptopp.a -o example.exe
BitfinexAPI.cpp: In static member function ‘static int BitfinexAPI::getBase64(const string&, std::__cxx11::string&)’:
BitfinexAPI.cpp:936:5: error: ‘byte’ was not declared in this scope
     byte buffer[1024] = {};
     ^~~~
BitfinexAPI.cpp:936:5: note: suggested alternative:
In file included from ../cryptopp/seckey.h:9:0,
                 from ../cryptopp/hmac.h:9,
                 from BitfinexAPI.cpp:37:
../cryptopp/config.h:222:23: note:   ‘CryptoPP::byte’
 typedef unsigned char byte;
                       ^~~~
BitfinexAPI.cpp:940:9: error: ‘buffer’ was not declared in this scope
         buffer[i] = content[i];
         ^~~~~~
BitfinexAPI.cpp:940:9: note: suggested alternative: ‘setbuffer’
         buffer[i] = content[i];
         ^~~~~~
         setbuffer
BitfinexAPI.cpp:943:21: error: ‘buffer’ was not declared in this scope
     StringSource ss(buffer, content.length(), true, new Base64Encoder( new StringSink(encoded), false));
                     ^~~~~~
BitfinexAPI.cpp:943:21: note: suggested alternative: ‘setbuffer’
     StringSource ss(buffer, content.length(), true, new Base64Encoder( new StringSink(encoded), false));
                     ^~~~~~
                     setbuffer
BitfinexAPI.cpp: In static member function ‘static int BitfinexAPI::getHmacSha384(const string&, const string&, std::__cxx11::string&)’:
BitfinexAPI.cpp:963:33: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
     SecByteBlock byteKey((const byte*)key.data(), key.size());
                                 ^~~~
BitfinexAPI.cpp:963:27: error: expected primary-expression before ‘const’
     SecByteBlock byteKey((const byte*)key.data(), key.size());
                           ^~~~~
BitfinexAPI.cpp:963:27: error: expected ‘)’ before ‘const’
@noloader
Copy link
Author

noloader commented Nov 28, 2017

This patch fixes the compile problem in a way that works with both Crypto++ 5.6.5 (and below) and Crypto++ 6.0 (and above):

i$ git diff
diff --git a/BitfinexAPI.cpp b/BitfinexAPI.cpp
index 151fe59..a940495 100644
--- a/BitfinexAPI.cpp
+++ b/BitfinexAPI.cpp
@@ -47,6 +47,11 @@ using std::to_string;



+// CRYPTOPP_NO_GLOBAL_BYTE signals byte is at CryptoPP::byte
+#if defined(CRYPTOPP_NO_GLOBAL_BYTE)
+using CryptoPP::byte;
+#endif
+
 //////////////////////////////////////////////////////////////////////////////
 // Constructor - destructor
 //////////////////////////////////////////////////////////////////////////////

@MMquant MMquant added the patch label Nov 28, 2017
@MMquant
Copy link
Owner

MMquant commented Nov 28, 2017

Should be patched now.

@MMquant MMquant closed this as completed Nov 28, 2017
@noloader
Copy link
Author

Thanks Petr. Sorry about the trouble it caused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants