sec: use a hashtable for lookup

This commit is contained in:
Daniel Cousens 2014-05-16 11:30:28 +10:00
parent 087ca551f5
commit da48c988f6

View file

@ -193,17 +193,17 @@ function secp256r1() {
return new X9ECParameters(curve, G, n, h);
}
// TODO: make this into a proper hashtable
function getSECCurveByName(name) {
if(name == "secp128r1") return secp128r1();
if(name == "secp160k1") return secp160k1();
if(name == "secp160r1") return secp160r1();
if(name == "secp192k1") return secp192k1();
if(name == "secp192r1") return secp192r1();
if(name == "secp224r1") return secp224r1();
if(name == "secp256k1") return secp256k1();
if(name == "secp256r1") return secp256r1();
return null;
return ({
"secp128r1": secp128r1,
"secp160k1": secp160k1,
"secp160r1": secp160r1,
"secp192k1": secp192k1,
"secp192r1": secp192r1,
"secp224r1": secp224r1,
"secp256k1": secp256k1,
"secp256r1": secp256r1
}[name])()
}
module.exports = getSECCurveByName;
module.exports = getSECCurveByName