Browse Source

[trac781] remove unused code, some style changes

Jelte Jansen 14 years ago
parent
commit
817462f1ea

+ 17 - 20
src/lib/crypto/crypto.cc

@@ -46,41 +46,43 @@ HashFunction* getHash(const Name& hash_name) {
 	}
 }
 
+    // Library needs to have been inited during the entire program
+    // should we make this a singleton? (for hsm we'll need more
+    // initialization, and dynamic loading)
+    LibraryInitializer init;
+
 } // local namespace
 
 namespace isc {
 namespace crypto {
 
-void doHMAC(const OutputBuffer& data, TSIGKey key, isc::dns::OutputBuffer& result) {
-
-    // needs to be in global scope; can we make a generalized
-    // subclassable singleton? (for hsm we'll need more initialization)
-    LibraryInitializer init;
-
-    // not used here, but we'd need a ctx
-
+void
+signHMAC(const OutputBuffer& data, TSIGKey key,
+         isc::dns::OutputBuffer& result)
+{
     // get algorithm from key, then 'translate' to Botan-specific algo
     HashFunction* hash = getHash(key.getAlgorithmName());
     HMAC::HMAC hmac(hash);
 
     // Take the 'secret' from the key
-    hmac.set_key(static_cast<const byte*>(key.getSecret()), key.getSecretLength());
+    hmac.set_key(static_cast<const byte*>(key.getSecret()),
+                 key.getSecretLength());
 
     // update the data from whatever we get (probably as a buffer)
-    hmac.update(static_cast<const byte*>(data.getData()), data.getLength());
+    hmac.update(static_cast<const byte*>(data.getData()),
+                data.getLength());
 
     // And generate the mac
     SecureVector<byte> b_result(hmac.final());
 
-
     // write mac to result
     result.writeData(b_result.begin(), b_result.size());
-
-    //std::cout << "HMAC SIG LEN: " << b_result.size() << std::endl;
-    //std::cout << "HMAC SIG LEN2: " << result.getLength() << std::endl;
 }
 
-bool verifyHMAC(const OutputBuffer& data, TSIGKey key, const isc::dns::OutputBuffer& result) {
+bool
+verifyHMAC(const OutputBuffer& data, TSIGKey key,
+           const isc::dns::OutputBuffer& result)
+{
     HashFunction* hash = getHash(key.getAlgorithmName());
     HMAC::HMAC hmac(hash);
     hmac.set_key(static_cast<const byte*>(key.getSecret()), key.getSecretLength());
@@ -113,11 +115,6 @@ TSIGKeyFromString(const std::string& str) {
 	
 	std::string secret_str = str.substr(pos + 1, pos2 - pos - 1);
 
-	/*
-	std::cout << "[XX] KEY NAME: " << key_name << std::endl;
-	std::cout << "[XX] KEY ALGO: " << algo_name << std::endl;
-	std::cout << "[XX] SECRET:   " << secret_str << std::endl;
-	*/
 	vector<uint8_t> secret;
 	decodeBase64(secret_str, secret);
 	unsigned char secret_b[secret.size()];

+ 8 - 27
src/lib/crypto/crypto.h

@@ -35,37 +35,18 @@
 namespace isc {
 namespace crypto {
 
-void doHMAC(const isc::dns::OutputBuffer& data, isc::dns::TSIGKey key, isc::dns::OutputBuffer& result);
-bool verifyHMAC(const isc::dns::OutputBuffer& data, isc::dns::TSIGKey key, const isc::dns::OutputBuffer& mac);
-isc::dns::TSIGKey TSIGKeyFromString(const std::string& str);
-std::string TSIGKeyToString(const isc::dns::TSIGKey& key);
+void signHMAC(const isc::dns::OutputBuffer& data,
+              isc::dns::TSIGKey key,
+              isc::dns::OutputBuffer& result);
 
-class Crypto {
-    static Crypto& getInstance();
-    virtual void init() = 0;
-    virtual void cleanup() = 0;
-};
+bool verifyHMAC(const isc::dns::OutputBuffer& data,
+                isc::dns::TSIGKey key,
+                const isc::dns::OutputBuffer& mac);
 
-/*
-class TSIGKeyImpl;
+isc::dns::TSIGKey TSIGKeyFromString(const std::string& str);
 
-class TSIGKey {
-public:
-    enum algorithms {
-        TSIG_HMAC_MD5 = 1,
-        TSIG_HMAC_SHA256 = 2
-    };
+std::string TSIGKeyToString(const isc::dns::TSIGKey& key);
 
-    TSIGKey(const std::string& str);
-    ~TSIGKey();
-    algorithms getAlgorithm();
-    const char* getSecret();
-    size_t getSecretLength();
-    
-private:
-    TSIGKeyImpl* impl_;
-};
-*/
 } // namespace crypto
 } // namespace isc
 

+ 0 - 7
src/lib/crypto/crypto_botan.h

@@ -22,13 +22,6 @@
 namespace isc {
 namespace crypto {
 
-class CryptoBotan : public Crypto {
-    void init() {};
-    void cleanup() {};
-};
-
-
-
 } // namespace crypto
 } // namespace isc
 

+ 1 - 1
src/lib/crypto/tests/crypto_unittests.cc

@@ -41,7 +41,7 @@ namespace {
 	    
 	    TSIGKey key = TSIGKeyFromString(key_str);
 	    
-	    doHMAC(data_buf, key, hmac_sig);
+	    signHMAC(data_buf, key, hmac_sig);
 	    checkBuffer(hmac_sig, expected_hmac, hmac_len);
 	}
 }