From: Chris Hofstaedtler Date: Wed, 3 Jan 2018 23:35:57 +0000 (+0100) Subject: Use algo constants where possible X-Git-Tag: dnsdist-1.3.0~173^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F6139%2Fhead;p=thirdparty%2Fpdns.git Use algo constants where possible --- diff --git a/pdns/dbdnsseckeeper.cc b/pdns/dbdnsseckeeper.cc index d006bac02a..ee5eb5fc0e 100644 --- a/pdns/dbdnsseckeeper.cc +++ b/pdns/dbdnsseckeeper.cc @@ -85,11 +85,11 @@ bool DNSSECKeeper::addKey(const DNSName& name, bool setSEPBit, int algorithm, in if(algorithm <= 10) throw runtime_error("Creating an algorithm " +std::to_string(algorithm)+" ("+algorithm2name(algorithm)+") key requires the size (in bits) to be passed."); else { - if(algorithm == 12 || algorithm == 13 || algorithm == 15) // GOST, ECDSAP256SHA256, ED25519 + if(algorithm == DNSSECKeeper::ECCGOST || algorithm == DNSSECKeeper::ECDSA256 || algorithm == DNSSECKeeper::ED25519) bits = 256; - else if(algorithm == 14) // ECDSAP384SHA384 + else if(algorithm == DNSSECKeeper::ECDSA384) bits = 384; - else if(algorithm == 16) // ED448 + else if(algorithm == DNSSECKeeper::ED448) bits = 456; else { throw runtime_error("Can not guess key size for algorithm "+std::to_string(algorithm)); @@ -163,8 +163,8 @@ DNSSECPrivateKey DNSSECKeeper::getKeyById(const DNSName& zname, unsigned int id) dpk.d_flags = kd.flags; dpk.d_algorithm = dkrc.d_algorithm; - if(dpk.d_algorithm == 5 && getNSEC3PARAM(zname)) { - dpk.d_algorithm += 2; + if(dpk.d_algorithm == DNSSECKeeper::RSASHA1 && getNSEC3PARAM(zname)) { + dpk.d_algorithm = DNSSECKeeper::RSASHA1NSEC3SHA1; } return dpk; @@ -485,9 +485,9 @@ DNSSECKeeper::keyset_t DNSSECKeeper::getKeys(const DNSName& zone, bool useCache) dpk.d_flags = kd.flags; dpk.d_algorithm = dkrc.d_algorithm; - if(dpk.d_algorithm == 5 && getNSEC3PARAM(zone)) { + if(dpk.d_algorithm == DNSSECKeeper::RSASHA1 && getNSEC3PARAM(zone)) { L< DNSCryptoKeyEngine::testMakers(unsigned int alg unsigned int bits; if(algo <= 10) bits=1024; - else if(algo == 12 || algo == 13 || algo == 15) // ECC-GOST or ECDSAP256SHA256 or ED25519 - bits=256; - else if(algo == 14) // ECDSAP384SHA384 + else if(algo == DNSSECKeeper::ECCGOST || algo == DNSSECKeeper::ECDSA256 || algo == DNSSECKeeper::ED25519) + bits = 256; + else if(algo == DNSSECKeeper::ECDSA384) bits = 384; - else if(algo == 16) // ED448 + else if(algo == DNSSECKeeper::ED448) bits = 456; else throw runtime_error("Can't guess key size for algorithm "+std::to_string(algo)); diff --git a/pdns/opensslsigners.cc b/pdns/opensslsigners.cc index 633c252789..eef5ca4384 100644 --- a/pdns/opensslsigners.cc +++ b/pdns/opensslsigners.cc @@ -278,14 +278,14 @@ DNSCryptoKeyEngine::storvector_t OpenSSLRSADNSCryptoKeyEngine::convertToISCVecto string algorithm=std::to_string(d_algorithm); switch(d_algorithm) { - case 5: - case 7: + case DNSSECKeeper::RSASHA1: + case DNSSECKeeper::RSASHA1NSEC3SHA1: algorithm += " (RSASHA1)"; break; - case 8: + case DNSSECKeeper::RSASHA256: algorithm += " (RSASHA256)"; break; - case 10: + case DNSSECKeeper::RSASHA512: algorithm += " (RSASHA512)"; break; default: @@ -305,20 +305,17 @@ DNSCryptoKeyEngine::storvector_t OpenSSLRSADNSCryptoKeyEngine::convertToISCVecto std::string OpenSSLRSADNSCryptoKeyEngine::hash(const std::string& orig) const { - if (d_algorithm == 5 || d_algorithm == 7) { - /* RSA SHA1 */ + if (d_algorithm == DNSSECKeeper::RSASHA1 || d_algorithm == DNSSECKeeper::RSASHA1NSEC3SHA1) { unsigned char hash[SHA_DIGEST_LENGTH]; SHA1((unsigned char*) orig.c_str(), orig.length(), hash); return string((char*) hash, sizeof(hash)); } - else if (d_algorithm == 8) { - /* RSA SHA256 */ + else if (d_algorithm == DNSSECKeeper::RSASHA256) { unsigned char hash[SHA256_DIGEST_LENGTH]; SHA256((unsigned char*) orig.c_str(), orig.length(), hash); return string((char*) hash, sizeof(hash)); } - else if (d_algorithm == 10) { - /* RSA SHA512 */ + else if (d_algorithm == DNSSECKeeper::RSASHA512) { unsigned char hash[SHA512_DIGEST_LENGTH]; SHA512((unsigned char*) orig.c_str(), orig.length(), hash); return string((char*) hash, sizeof(hash)); diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index f409fd0591..464964df1f 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -247,7 +247,7 @@ int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, const vect DNSKEYRecordContent dkrc; shared_ptr(DNSCryptoKeyEngine::makeFromISCString(dkrc, kd.content)); - if(dkrc.d_algorithm == 5) { + if(dkrc.d_algorithm == DNSSECKeeper::RSASHA1) { cout<<"[Warning] zone '"< dke(DNSCryptoKeyEngine::makeFromISCString(dkrc, keyData)); dpk.d_algorithm = dkrc.d_algorithm; // TODO remove in 4.2.0 - if(dpk.d_algorithm == 7) - dpk.d_algorithm = 5; + if(dpk.d_algorithm == DNSSECKeeper::RSASHA1NSEC3SHA1) + dpk.d_algorithm = DNSSECKeeper::RSASHA1; if (keyOrZone) dpk.d_flags = 257;