X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5c19dc3ae3bd8e40a9c028b0deddd50ff337692c..dd5fb164cf5b32c462296bc65e289e100f74b59a:/OSX/libsecurity_utilities/lib/hashing.h?ds=sidebyside diff --git a/OSX/libsecurity_utilities/lib/hashing.h b/OSX/libsecurity_utilities/lib/hashing.h index a54d2b4e..b9117998 100644 --- a/OSX/libsecurity_utilities/lib/hashing.h +++ b/OSX/libsecurity_utilities/lib/hashing.h @@ -31,6 +31,7 @@ #include #include #include +#include #include // SPI slated to become API namespace Security { @@ -52,7 +53,7 @@ public: // // If you write template code based on "any static hasher", you can directly tap here // (and learn the actual hash in use through the match on _HashType). But note that -// a DynamicHash is not a subclass of Hash, though a DynamicHashInstance will be, duck-like. +// a DynamicHash is not a subclass of Hash. // template class Hash : public Hashing { @@ -93,12 +94,14 @@ public: // This isn't a subclass of Hash (which is static-fast), but it's duck-typed to it. // Note that digestLength is a function here, not a constant. Obviously. // -class DynamicHash : public Hashing { +class DynamicHash : public RefCount, public Hashing { public: virtual ~DynamicHash(); virtual size_t digestLength() const = 0; virtual void update(const void *data, size_t length) = 0; + template + void update(const _Dataoid &doid) { this->update(doid.data(), doid.length()); } virtual void finish(Byte *digest) = 0; void operator () (const void *data, size_t length) @@ -109,30 +112,6 @@ public: }; -// -// Make a DynamicHash from a static Hash class. -// -template -class DynamicHashInstance : public DynamicHash, public _HashType { -public: - // (wish we had C++0x already...) - DynamicHashInstance() { } - template - DynamicHashInstance(const Arg1 &arg1) : _HashType(arg1) { } - template - DynamicHashInstance(const Arg1 &arg1, const Arg2 &arg2) : _HashType(arg1, arg2) { } - template - DynamicHashInstance(const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) : _HashType(arg1, arg2, arg3) { } - - size_t digestLength() const - { return _HashType::digestLength; } - void update(const void *data, size_t length) - { return _HashType::update(data, length); } - void finish(unsigned char *digest) - { return _HashType::finish(digest); } -}; - - // // Make a DynamicHash from a CommonCrypto hash algorithm identifier // @@ -159,9 +138,9 @@ private: // object out there by asking nicely (by default, calling its getHash() method). // template -class MakeHash : public std::auto_ptr { +class MakeHash : public RefPointer { public: - MakeHash(const _Giver *giver) : std::auto_ptr((giver->*_fetcher)()) { } + MakeHash(const _Giver *giver) : RefPointer((giver->*_fetcher)()) { } operator DynamicHash *() const { return this->get(); } };