]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_utilities/lib/hashing.h
Security-58286.270.3.0.1.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / hashing.h
index a54d2b4e375364cc8b971a6cd6cd504d118f307b..b9117998286771b30d5f2d319a7236393a8556b9 100644 (file)
@@ -31,6 +31,7 @@
 #include <cstring>
 #include <memory>
 #include <sys/types.h>
+#include <security_utilities/refcount.h>
 #include <CommonCrypto/CommonDigestSPI.h>      // 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 <uint32_t _size, class _HashType>
 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<typename _Dataoid>
+       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 _HashType>
-class DynamicHashInstance : public DynamicHash, public _HashType {
-public:
-       // (wish we had C++0x already...)
-       DynamicHashInstance() { }
-       template <class Arg1>
-       DynamicHashInstance(const Arg1 &arg1) : _HashType(arg1) { }
-       template <class Arg1, class Arg2>
-       DynamicHashInstance(const Arg1 &arg1, const Arg2 &arg2) : _HashType(arg1, arg2) { }
-       template <class Arg1, class Arg2, class Arg3>
-       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 _Giver, DynamicHash *(_Giver::*_fetcher)() const = &_Giver::getHash>
-class MakeHash : public std::auto_ptr<DynamicHash> {
+class MakeHash : public RefPointer<DynamicHash> {
 public:
-       MakeHash(const _Giver *giver) : std::auto_ptr<DynamicHash>((giver->*_fetcher)()) { }
+       MakeHash(const _Giver *giver) : RefPointer<DynamicHash>((giver->*_fetcher)()) { }
        
        operator DynamicHash *() const { return this->get(); }
 };