Browse Source

[trac781] add deleteHMAC()

Jelte Jansen 14 years ago
parent
commit
7be4a7e7f8

+ 5 - 0
src/lib/cryptolink/crypto_hmac.cc

@@ -228,5 +228,10 @@ verifyHMAC(const void* data, const size_t data_len, const void* secret,
     return (hmac->verify(sig, sig_len));
 }
 
+void
+deleteHMAC(HMAC* hmac) {
+    delete hmac;
+}
+
 } // namespace cryptolink
 } // namespace isc

+ 3 - 0
src/lib/cryptolink/crypto_hmac.h

@@ -199,6 +199,9 @@ bool verifyHMAC(const void* data,
                 const void* sig,
                 const size_t sig_len);
 
+/// \brief Delete an HMAC object
+void deleteHMAC(HMAC* hmac);
+
 } // namespace cryptolink
 } // namespace isc
 

+ 12 - 1
src/lib/cryptolink/cryptolink.h

@@ -112,9 +112,16 @@ class CryptoLinkImpl;
 /// have private constructors, it is declared a friend class of these
 /// classes.
 ///
+/// Since these factory functions return bare pointers, we also provide
+/// deleter functions for them (e.g. deleteHMAC()), so that a caller
+/// can use that to make sure it uses the correct delete operator (the
+/// one defined at compilation time of this library). A way to make
+/// sure you do not forget this, is to place the result of the create
+/// functions in a shared_ptr with the corresponding deleter function.
+///
 /// \note All other classes within cryptolink should have private
 /// constructors as well, and should have a factory function from
-/// CryptoLink.
+/// CryptoLink, and a deleter function.
 ///
 // Internal note: we can use this class later to initialize and manage
 // dynamic (PKCS#11) libs
@@ -161,6 +168,10 @@ public:
     /// algorithm, and use the digest as the secret for this HMAC
     /// operation
     ///
+    /// If you want to safely delete objects created with this method,
+    /// you can use the function deleteHMAC() as defined in
+    /// crypto_hmac.h
+    ///
     /// \exception UnsupportedAlgorithmException if the given algorithm
     ///            is unknown or not supported by the underlying library
     /// \exception InvalidKeyLength if the given key secret_len is bad