diff options
author | Nils Kenneweg <github@ovt.me> | 2013-09-10 13:04:56 +0200 |
---|---|---|
committer | Nils Kenneweg <github@ovt.me> | 2013-09-10 13:04:56 +0200 |
commit | 1fdb124244137ed08ef3c9405ac848aa8cede2b4 (patch) | |
tree | 551be4cafaade27783a8a11ae09b33427eb4a1e3 | |
parent | 97784e839f69e99057e0f40a01bd5bbee5c58d39 (diff) | |
download | sjcl-origin/feature/serialization.zip sjcl-origin/feature/serialization.tar.gz sjcl-origin/feature/serialization.tar.bz2 |
deserialization done.origin/feature/serialization
-rw-r--r-- | core/ecc.js | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/core/ecc.js b/core/ecc.js index b8e989e..6aba569 100644 --- a/core/ecc.js +++ b/core/ecc.js @@ -306,14 +306,22 @@ sjcl.ecc.curveName = function (curve) { }; sjcl.ecc.deserialize = function (key) { - if (!key || !key.curve) { throw new sjcl.exception.invalid("invalid serialization"); } - var constructor = sjcl.ecc[key.type]; - if (!constructor || !constructor.publicKey) { throw new sjcl.exception.invalid("unknown key type"); } - if (key.secret) { - if (!key.exponent) { throw new sjcl.exception.invalid("invalid point"); } + var types = ["elGamal", "ecdsa"]; + + if (!key || !key.curve || !sjcl.ecc.curves[key.curve]) { throw new sjcl.exception.invalid("invalid serialization"); } + if (types.indexOf(key.type) === -1) { throw new sjcl.exception.invalid("invalid type"); } + + var curve = sjcl.ecc.curves[key.curve]; + + if (key.secretKey) { + if (!key.exponent) { throw new sjcl.exception.invalid("invalid exponent"); } + var exponent = new sjcl.bn(key.exponent); + return new sjcl.ecc[key.type].secretKey(curve, exponent); } else { - if (!key.point || !key.point.x || !key.point.y) { throw new sjcl.exception.invalid("invalid point"); } + if (!key.point) { throw new sjcl.exception.invalid("invalid point"); } + var point = curve.fromBits(sjcl.codec.hex.toBits(key.point)); + return new sjcl.ecc[key.type].publicKey(curve, point); } }; |