text
stringlengths 0
2.2M
|
---|
Seeded1024BitHashingAlgorithm::result_type
|
Seeded1024BitHashingAlgorithm::operator()(const char *data, size_t length) {
|
return someSeededHash(d_seed, 128, data, length);
|
}
|
// ============================================================================
|
// MAIN PROGRAM
|
// ----------------------------------------------------------------------------
|
int main(int argc, char *argv[])
|
{
|
int test = argc > 1 ? atoi(argv[1]) : 0;
|
bool verbose = argc > 2;
|
bool veryVerbose = argc > 3;
|
bool veryVeryVerbose = argc > 4;
|
bool veryVeryVeryVerbose = argc > 5;
|
(void)veryVeryVerbose; // suppress warning
|
(void)veryVeryVeryVerbose; // suppress warning
|
printf("TEST " __FILE__ " CASE %d\n", test);
|
switch (test) { case 0:
|
case 4: {
|
// --------------------------------------------------------------------
|
// USAGE EXAMPLE
|
// The seed generator can be used to ease the creation and usage of
|
// more complicated components such as hashing algorithms.
|
//
|
// Concerns:
|
//: 1 The usage example provided in the component header file compiles,
|
//: links, and runs as shown.
|
//
|
// Plan:
|
//: 1 Run the usage example (C-1)
|
//
|
// Testing:
|
// USAGE EXAMPLE
|
// --------------------------------------------------------------------
|
if (verbose) printf("USAGE EXAMPLE\n"
|
"=============\n");
|
//..
|
// Now, we generate some data that we want to hash.
|
//..
|
const char *data[] = { "asdf",
|
"qwer",
|
"gskgf",
|
"ujkagad",
|
"rwwfwe", };
|
enum { NUM_STRINGS = sizeof data / sizeof *data };
|
//..
|
// Finally, we can hash the data the same way using all of the different
|
// hashing algorithms. The seed generator allows us to abstract away the
|
// different requirements each algorithm has on seed size. Each algorithm will
|
// produce different output because it has been supplied with a different seed.
|
//..
|
MockRNG rng;
|
SeedGenerator<MockRNG> seedGen(rng);
|
SeededHash<Seeded32BitHashingAlgorithm> hashAlg32BitSeed(seedGen);
|
SeededHash<Seeded64BitHashingAlgorithm> hashAlg64BitSeed(seedGen);
|
SeededHash<Seeded1024BitHashingAlgorithm> hashAlg1024BitSeed(seedGen);
|
for (int i = 0; i < NUM_STRINGS; ++i) {
|
unsigned int hash32BitSeed = hashAlg32BitSeed(data[i],
|
strlen(data[i]));
|
unsigned int hash64BitSeed = hashAlg64BitSeed(data[i],
|
strlen(data[i]));
|
unsigned int hash1024BitSeed = hashAlg1024BitSeed(data[i],
|
strlen(data[i]));
|
if (veryVerbose) printf("Asserting hashes of %s come out"
|
" different\n", data[i]);
|
ASSERT(hash32BitSeed != hash64BitSeed);
|
ASSERT(hash32BitSeed != hash1024BitSeed);
|
ASSERT(hash1024BitSeed != hash64BitSeed);
|
}
|
} break;
|
case 3: {
|
// --------------------------------------------------------------------
|
// TESTING 'generateSeed'
|
// Ensure that the 'generateSeed' method is publicly callable,
|
// returns the expected values.
|
//
|
// Concerns:
|
//: 1 The method is publicly callable with a pointer and a length.
|
//:
|
//: 2 The supplied RNG is used to fill memory.
|
//:
|
//: 3 The method writes to every byte specified.
|
//:
|
//: 4 The method does not write more memory than specified.
|
//:
|
//: 5 A size of zero results in no calls to the RNG and no writes to
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.