summaryrefslogtreecommitdiff
path: root/cryptlib.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-01-28 05:43:24 -0500
committerJeffrey Walton <noloader@gmail.com>2017-01-28 05:43:24 -0500
commit6f7339c81b26985a830da6efe1da59e3897f6b71 (patch)
tree87aeec349c78993cc7083b19fa6eb1eb922ad78b /cryptlib.h
parente757fad5bad98789d044aaa96fb4ec4192b69eb6 (diff)
downloadcryptopp-git-6f7339c81b26985a830da6efe1da59e3897f6b71.tar.gz
Add BuildVersion and RuntimeVersion functions (Issue 371)
These function are intended to catch mining and matching of library versions. BuildVersion provides CRYPTOPP_VERSION when the shared object was built. RuntimeVersion provides CRYPTOPP_VERSION the app compiled against, which could be different than the shared object's version
Diffstat (limited to 'cryptlib.h')
-rw-r--r--cryptlib.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/cryptlib.h b/cryptlib.h
index 0e6011bc..dcb3ac3a 100644
--- a/cryptlib.h
+++ b/cryptlib.h
@@ -2914,6 +2914,76 @@ public:
virtual void BEREncode(BufferedTransformation &bt) const {DEREncode(bt);}
};
+//! \brief Specifies the build-time version of the library
+//! \returns integer representing the build-time version
+//! \details BuildVersion can help detect inadvertent mixing and matching of library
+//! versions. When using Crypto++ distributed by a third party, BuildVersion()
+//! records the version of the shared object that was built by the third party.
+//! The BuildVersion() record resides in <tt>cryptlib.o</tt> on Unix compatibles
+//! and <tt>cryptlib.obj</tt> on Windows. It does not change when an app links
+//! to the library.
+//! \details BuildVersion() is declared with C linkage (<tt>extern "C"</tt>) within the
+//! CryptoPP namespace to help programs locate the symbol. If the symbol is present, then
+//! the library version is 5.7 or above. If it is missing, then the library version is
+//! 5.6.5 or below.
+//! \details The function could be used as shown below.
+//! <pre>
+//! if (BuildVersion() != RuntimeVersion())
+//! {
+//! cout << "Potential version mismatch" << endl;
+//!
+//! const int bmaj = (BuildVersion() / 100U) % 10;
+//! const int bmin = (BuildVersion() / 10U) % 10;
+//! const int rmaj = (RuntimeVersion() / 100U) % 10;
+//! const int rmin = (RuntimeVersion() / 10U) % 10;
+//!
+//! if(bmaj != rmaj)
+//! cout << "Major version mismatch" << endl;
+//! else if(bmin != rmin)
+//! cout << "Minor version mismatch" << endl;
+//! }
+//! </pre>
+//! \sa RuntimeVersion(), <A HREF="http://github.com/weidai11/cryptopp/issues/371">GitHub Issue 371</A>.
+//! \since Crypto++ 5.7
+extern "C" {
+ int BuildVersion();
+} // C linkage
+
+//! \brief Specifies the runtime version of the library
+//! \returns integer representing the runtime version
+//! \details RuntimeVersion() can help detect inadvertent mixing and matching of library
+//! versions. When using Crypto++ distributed by a third party, RuntimeVersion()
+//! records the version of the headers used by the app when the app is compiled.
+//! \details RuntimeVersion() is declared with C linkage (<tt>extern "C"</tt>) within the
+//! CryptoPP namespace to help programs locate the symbol. If the symbol is present, then
+//! the library version is 5.7 or above. If it is missing, then the library version is
+//! 5.6.5 or below.
+//! \details The function could be used as shown below.
+//! <pre>
+//! if (BuildVersion() != RuntimeVersion())
+//! {
+//! cout << "Potential version mismatch" << endl;
+//!
+//! const int bmaj = (BuildVersion() / 100U) % 10;
+//! const int bmin = (BuildVersion() / 10U) % 10;
+//! const int rmaj = (RuntimeVersion() / 100U) % 10;
+//! const int rmin = (RuntimeVersion() / 10U) % 10;
+//!
+//! if(bmaj != rmaj)
+//! cout << "Major version mismatch" << endl;
+//! else if(bmin != rmin)
+//! cout << "Minor version mismatch" << endl;
+//! }
+//! </pre>
+//! \sa BuildVersion(), <A HREF="http://github.com/weidai11/cryptopp/issues/371">GitHub Issue 371</A>.
+//! \since Crypto++ 5.7
+extern "C" {
+inline int RuntimeVersion()
+{
+ return CRYPTOPP_VERSION;
+}
+} // C linkage
+
NAMESPACE_END
#if CRYPTOPP_MSC_VERSION