Permalink
Browse files

passes all tests again, surprisingly!

  • Loading branch information...
1 parent 0a89d7e commit 36ee93998c5eff975265abebbd17bd75bbe39d5d @substack committed Mar 1, 2011
Showing with 34 additions and 13 deletions.
  1. +9 −3 dss.js
  2. +25 −10 test/keys.js
View
@@ -44,6 +44,7 @@ function DSS (keys) {
DSS.fromFields = function (fields) {
var dss = Object.create(DSS.prototype);
+ dss.algorithm = 'dss';
dss.fields = fields;
var bufs = 'pqgy'.split('').map(function (name) {
@@ -90,8 +91,13 @@ DSS.prototype.challenge = function (ebuf, params) {
return Buffers([ K_S, f.toBuffer('mpint'), signed ]).slice();
};
-DSS.prototype.format = function (format, kt, email) {
- return Format(format, this.keys, kt, email);
+DSS.prototype.key = function (kt) {
+ return {
+ data : this.keys[kt].toString('base64'),
+ format : (function (format, aux) {
+ return Format(format, this, kt, aux)
+ }).bind(this)
+ }
};
// Generate two primes p and q to the Digital Signature Standard (DSS)
@@ -122,5 +128,5 @@ DSS.generate = function () {
var x = q.sub(1).rand().add(1); // private key
var y = g.powm(x, p); // public key
- return DSS({ p : p, q : q, g : g, y : y, x : x });
+ return DSS.fromFields({ p : p, q : q, g : g, y : y, x : x });
};
View
@@ -8,18 +8,33 @@ var Buffers = require('buffers');
exports.packParseKey = function () {
var keypair = keyx.generate('dss');
- assert.throws(function () {
- keypair.format('ssh2');
- });
+ var ssh2 = {
+ priv : keypair.key('private').format('ssh2'),
+ pub : keypair.key('public').format('ssh2'),
+ };
- var ssh2 = key.format('ssh2', 'private');
- var kssh2 = keyx.parse(ssh2);
assert.eql(
- key.data,
- kssh2.data
+ keypair.key('private').data,
+ keyx.parse(ssh2.priv).data
);
- var openssh = key.format('openssh', 'moo@moo.com');
- var kopenssh = keyx.parse(openssh);
- assert.eql(key.data, kopenssh.data);
+ assert.eql(
+ keypair.key('public').data,
+ keyx.parse(ssh2.pub).data
+ );
+
+ var openssh = {
+ priv : keypair.key('private').format('openssh'),
+ pub : keypair.key('public').format('openssh'),
+ };
+
+ assert.eql(
+ keypair.key('private').data,
+ keyx.parse(openssh.priv).data
+ );
+
+ assert.eql(
+ keypair.key('public').data,
+ keyx.parse(openssh.pub).data
+ );
};

0 comments on commit 36ee939

Please sign in to comment.