Partial cut-over to static local strings for DefaultChannel() and AadChannel(). Cout-over DEFAULT_CHANNEL and AAD_CHANNEL to use them behind the scenes

pull/35/head
Jeffrey Walton 2015-07-31 08:23:53 -04:00
parent 8796c9e684
commit d935fd80ba
4 changed files with 32 additions and 25 deletions

View File

@ -32,9 +32,8 @@ CRYPTOPP_COMPILE_ASSERT(sizeof(word64) == 8);
CRYPTOPP_COMPILE_ASSERT(sizeof(dword) == 2*sizeof(word)); CRYPTOPP_COMPILE_ASSERT(sizeof(dword) == 2*sizeof(word));
#endif #endif
const std::string DEFAULT_CHANNEL; const std::string DEFAULT_CHANNEL = DefaultChannel();
const std::string AAD_CHANNEL = "AAD"; const std::string AAD_CHANNEL = AadChannel();
const std::string &BufferedTransformation::NULL_CHANNEL = DEFAULT_CHANNEL;
class NullNameValuePairs : public NameValuePairs class NullNameValuePairs : public NameValuePairs
{ {

View File

@ -768,11 +768,21 @@ public:
bool Wait(unsigned long milliseconds, CallStack const& callStack); 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; 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; 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 //! 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 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BufferedTransformation : public Algorithm, public Waitable
{ {
public: public:
// placed up here for CW8
static const std::string &NULL_CHANNEL; // same as DEFAULT_CHANNEL, for backwards compatibility
BufferedTransformation() : Algorithm(false) {} BufferedTransformation() : Algorithm(false) {}
@ -929,18 +937,18 @@ public:
size_t PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const; size_t PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const;
//! move transferMax bytes of the buffered output to target as input //! 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;} {TransferTo2(target, transferMax, channel); return transferMax;}
//! discard skipMax bytes from the output buffer //! discard skipMax bytes from the output buffer
virtual lword Skip(lword skipMax=LWORD_MAX); virtual lword Skip(lword skipMax=LWORD_MAX);
//! copy copyMax bytes of the buffered output to target as input //! 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);} {return CopyRangeTo(target, 0, copyMax, channel);}
//! copy copyMax bytes of the buffered output, starting at position (relative to current position), to target as input //! 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;} {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel); return i-position;}
#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
@ -965,18 +973,18 @@ public:
//! skip count number of messages //! skip count number of messages
virtual unsigned int SkipMessages(unsigned int count=UINT_MAX); 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;} {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(); 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);} {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 bool GetNextMessageSeries() {return false;}
virtual unsigned int NumberOfMessagesInThisSeries() const {return NumberOfMessages();} virtual unsigned int NumberOfMessagesInThisSeries() const {return NumberOfMessages();}
@ -986,13 +994,13 @@ public:
//! \name NON-BLOCKING TRANSFER OF OUTPUT //! \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 //! 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 //! 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 //! 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 //! 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 //! \name CHANNELS

View File

@ -61,7 +61,7 @@ const std::string & GetRequiredDatum(const TestData &data, const char *name)
return i->second; 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)) while (source.MaxRetrievable() > (finish ? 0 : 4096))
{ {
@ -492,16 +492,16 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid
if (macAtBegin) if (macAtBegin)
RandomizedTransfer(sm, df, true); RandomizedTransfer(sm, df, true);
sh.CopyTo(df, LWORD_MAX, AAD_CHANNEL); sh.CopyTo(df, LWORD_MAX, AadChannel());
RandomizedTransfer(sc, df, true); RandomizedTransfer(sc, df, true);
sf.CopyTo(df, LWORD_MAX, AAD_CHANNEL); sf.CopyTo(df, LWORD_MAX, AadChannel());
if (!macAtBegin) if (!macAtBegin)
RandomizedTransfer(sm, df, true); RandomizedTransfer(sm, df, true);
df.MessageEnd(); df.MessageEnd();
RandomizedTransfer(sh, ef, true, AAD_CHANNEL); RandomizedTransfer(sh, ef, true, AadChannel());
RandomizedTransfer(sp, ef, true); RandomizedTransfer(sp, ef, true);
RandomizedTransfer(sf, ef, true, AAD_CHANNEL); RandomizedTransfer(sf, ef, true, AadChannel());
ef.MessageEnd(); ef.MessageEnd();
if (test == "Encrypt" && encrypted != ciphertext+mac) if (test == "Encrypt" && encrypted != ciphertext+mac)

View File

@ -621,7 +621,7 @@ void SecretShareFile(int threshold, int nShares, const char *filename, const cha
channel = WordToString<word32>(i); channel = WordToString<word32>(i);
fileSinks[i]->Put((byte *)channel.data(), 4); fileSinks[i]->Put((byte *)channel.data(), 4);
channelSwitch->AddRoute(channel, *fileSinks[i], DEFAULT_CHANNEL); channelSwitch->AddRoute(channel, *fileSinks[i], DefaultChannel());
} }
source.PumpAll(); source.PumpAll();
@ -671,7 +671,7 @@ void InformationDisperseFile(int threshold, int nShares, const char *filename)
channel = WordToString<word32>(i); channel = WordToString<word32>(i);
fileSinks[i]->Put((byte *)channel.data(), 4); fileSinks[i]->Put((byte *)channel.data(), 4);
channelSwitch->AddRoute(channel, *fileSinks[i], DEFAULT_CHANNEL); channelSwitch->AddRoute(channel, *fileSinks[i], DefaultChannel());
} }
source.PumpAll(); source.PumpAll();