diff options
author | Jeffrey Walton <noloader@gmail.com> | 2015-07-31 08:23:53 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2015-07-31 08:23:53 -0400 |
commit | d935fd80ba0aaf3e40f7023f7ec02cb32e27e688 (patch) | |
tree | 14428e37232bb88dd8c7226c8250fc73943c472c | |
parent | 8796c9e684e2e4056821e4485dc1180d82767181 (diff) | |
download | cryptopp-git-d935fd80ba0aaf3e40f7023f7ec02cb32e27e688.tar.gz |
Partial cut-over to static local strings for DefaultChannel() and AadChannel(). Cout-over DEFAULT_CHANNEL and AAD_CHANNEL to use them behind the scenes
-rw-r--r-- | cryptlib.cpp | 5 | ||||
-rw-r--r-- | cryptlib.h | 38 | ||||
-rw-r--r-- | datatest.cpp | 10 | ||||
-rw-r--r-- | test.cpp | 4 |
4 files changed, 32 insertions, 25 deletions
diff --git a/cryptlib.cpp b/cryptlib.cpp index 43df08b2..2ded98c2 100644 --- a/cryptlib.cpp +++ b/cryptlib.cpp @@ -32,9 +32,8 @@ CRYPTOPP_COMPILE_ASSERT(sizeof(word64) == 8); CRYPTOPP_COMPILE_ASSERT(sizeof(dword) == 2*sizeof(word)); #endif -const std::string DEFAULT_CHANNEL; -const std::string AAD_CHANNEL = "AAD"; -const std::string &BufferedTransformation::NULL_CHANNEL = DEFAULT_CHANNEL; +const std::string DEFAULT_CHANNEL = DefaultChannel(); +const std::string AAD_CHANNEL = AadChannel(); class NullNameValuePairs : public NameValuePairs { @@ -768,11 +768,21 @@ public: bool Wait(unsigned long milliseconds, CallStack const& callStack); }; -//! the default channel for BufferedTransformation, equal to the empty std::string +//! the default channel for BufferedTransformation, equal to the empty string. +// New code should call the DefaultChannel() function. extern CRYPTOPP_DLL const std::string DEFAULT_CHANNEL; +inline static const std::string& DefaultChannel() { + static const std::string channel = ""; + return channel; +} -//! channel for additional authenticated data, equal to "AAD" +//! channel for additional authenticated data, equal to the string "AAD". +// New code should call AadChannel() function. extern CRYPTOPP_DLL const std::string AAD_CHANNEL; +inline static const std::string& AadChannel() { + static const std::string channel = "AAD"; + return channel; +} //! interface for buffered transformations @@ -803,8 +813,6 @@ extern CRYPTOPP_DLL const std::string AAD_CHANNEL; class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BufferedTransformation : public Algorithm, public Waitable { public: - // placed up here for CW8 - static const std::string &NULL_CHANNEL; // same as DEFAULT_CHANNEL, for backwards compatibility BufferedTransformation() : Algorithm(false) {} @@ -929,18 +937,18 @@ public: size_t PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const; //! move transferMax bytes of the buffered output to target as input - lword TransferTo(BufferedTransformation &target, lword transferMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) + lword TransferTo(BufferedTransformation &target, lword transferMax=LWORD_MAX, const std::string &channel=DefaultChannel()) {TransferTo2(target, transferMax, channel); return transferMax;} //! discard skipMax bytes from the output buffer virtual lword Skip(lword skipMax=LWORD_MAX); //! copy copyMax bytes of the buffered output to target as input - lword CopyTo(BufferedTransformation &target, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const + lword CopyTo(BufferedTransformation &target, lword copyMax=LWORD_MAX, const std::string &channel=DefaultChannel()) const {return CopyRangeTo(target, 0, copyMax, channel);} //! copy copyMax bytes of the buffered output, starting at position (relative to current position), to target as input - lword CopyRangeTo(BufferedTransformation &target, lword position, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const + lword CopyRangeTo(BufferedTransformation &target, lword position, lword copyMax=LWORD_MAX, const std::string &channel=DefaultChannel()) const {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel); return i-position;} #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY @@ -965,18 +973,18 @@ public: //! skip count number of messages virtual unsigned int SkipMessages(unsigned int count=UINT_MAX); //! - unsigned int TransferMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) + unsigned int TransferMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DefaultChannel()) {TransferMessagesTo2(target, count, channel); return count;} //! - unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const; + unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DefaultChannel()) const; //! virtual void SkipAll(); //! - void TransferAllTo(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL) + void TransferAllTo(BufferedTransformation &target, const std::string &channel=DefaultChannel()) {TransferAllTo2(target, channel);} //! - void CopyAllTo(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL) const; + void CopyAllTo(BufferedTransformation &target, const std::string &channel=DefaultChannel()) const; virtual bool GetNextMessageSeries() {return false;} virtual unsigned int NumberOfMessagesInThisSeries() const {return NumberOfMessages();} @@ -986,13 +994,13 @@ public: //! \name NON-BLOCKING TRANSFER OF OUTPUT //@{ //! upon return, byteCount contains number of bytes that have finished being transfered, and returns the number of bytes left in the current transfer block - virtual size_t TransferTo2(BufferedTransformation &target, lword &byteCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) =0; + virtual size_t TransferTo2(BufferedTransformation &target, lword &byteCount, const std::string &channel=DefaultChannel(), bool blocking=true) =0; //! upon return, begin contains the start position of data yet to be finished copying, and returns the number of bytes left in the current transfer block - virtual size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const =0; + virtual size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DefaultChannel(), bool blocking=true) const =0; //! upon return, messageCount contains number of messages that have finished being transfered, and returns the number of bytes left in the current transfer block - size_t TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); + size_t TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel=DefaultChannel(), bool blocking=true); //! returns the number of bytes left in the current transfer block - size_t TransferAllTo2(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); + size_t TransferAllTo2(BufferedTransformation &target, const std::string &channel=DefaultChannel(), bool blocking=true); //@} //! \name CHANNELS diff --git a/datatest.cpp b/datatest.cpp index d0f69c6d..5595c4a1 100644 --- a/datatest.cpp +++ b/datatest.cpp @@ -61,7 +61,7 @@ const std::string & GetRequiredDatum(const TestData &data, const char *name) return i->second; } -void RandomizedTransfer(BufferedTransformation &source, BufferedTransformation &target, bool finish, const std::string &channel=DEFAULT_CHANNEL) +void RandomizedTransfer(BufferedTransformation &source, BufferedTransformation &target, bool finish, const std::string &channel=DefaultChannel()) { while (source.MaxRetrievable() > (finish ? 0 : 4096)) { @@ -492,16 +492,16 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid if (macAtBegin) RandomizedTransfer(sm, df, true); - sh.CopyTo(df, LWORD_MAX, AAD_CHANNEL); + sh.CopyTo(df, LWORD_MAX, AadChannel()); RandomizedTransfer(sc, df, true); - sf.CopyTo(df, LWORD_MAX, AAD_CHANNEL); + sf.CopyTo(df, LWORD_MAX, AadChannel()); if (!macAtBegin) RandomizedTransfer(sm, df, true); df.MessageEnd(); - RandomizedTransfer(sh, ef, true, AAD_CHANNEL); + RandomizedTransfer(sh, ef, true, AadChannel()); RandomizedTransfer(sp, ef, true); - RandomizedTransfer(sf, ef, true, AAD_CHANNEL); + RandomizedTransfer(sf, ef, true, AadChannel()); ef.MessageEnd(); if (test == "Encrypt" && encrypted != ciphertext+mac) @@ -621,7 +621,7 @@ void SecretShareFile(int threshold, int nShares, const char *filename, const cha channel = WordToString<word32>(i); fileSinks[i]->Put((byte *)channel.data(), 4); - channelSwitch->AddRoute(channel, *fileSinks[i], DEFAULT_CHANNEL); + channelSwitch->AddRoute(channel, *fileSinks[i], DefaultChannel()); } source.PumpAll(); @@ -671,7 +671,7 @@ void InformationDisperseFile(int threshold, int nShares, const char *filename) channel = WordToString<word32>(i); fileSinks[i]->Put((byte *)channel.data(), 4); - channelSwitch->AddRoute(channel, *fileSinks[i], DEFAULT_CHANNEL); + channelSwitch->AddRoute(channel, *fileSinks[i], DefaultChannel()); } source.PumpAll(); |