Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Modify test.js to use Node 0.2.0 (and possibly earlier) style require("assert") instead of mjsunit #3

wants to merge 1 commit into from

1 participant


I've updated test.js to require("assert") instead of mjsunit.

@cjc cjc closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 11, 2010
  1. @cjc
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 8 deletions.
  1. +4 −1 README
  2. +7 −7 test.js
@@ -4,6 +4,9 @@ node-crypto
A wrapper around openssl for node.js, currently exposing Hashing, Signing
and Verifying methods.
+Version 0.0.5 : test.js now uses assert to match Node 0.2.0
Version 0.0.5 : test.js now uses mjsunit
Version 0.0.4 : Added package.json and updated tests to latest node version.
@@ -23,4 +26,4 @@ base64 encoded strings.
The encrypt / decrypt methods work with binary, hex or base64 encodings,
with streaming.
-See test.js for example usage.
+See test.js for example usage.
14 test.js
@@ -1,12 +1,12 @@
var crypto=require("./crypto");
var sys=require("sys");
var fs=require("fs");
-var test=require("mjsunit");
+var test=require("assert");
// Test HMAC
var h1 = (new crypto.Hmac).init("sha1", "Node").update("some data").update("to hmac").digest("hex");
-test.assertEquals(h1, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892', "test HMAC");
+test.equal(h1, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892', "test HMAC");
// Test hashing
var a0 = (new crypto.Hash).init("sha1").update("Test123").digest("hex");
@@ -17,7 +17,7 @@ var a3 = (new crypto.Hash).init("sha512").update("Test123").digest(); // binary
// Test multiple updates to same hash
var h1 = (new crypto.Hash).init("sha1").update("Test123").digest("hex");
var h2 = (new crypto.Hash).init("sha1").update("Test").update("123").digest("hex");
-test.assertEquals(h1, h2, "multipled updates");
+test.equal(h1, h2, "multipled updates");
// Load our public and private keys
@@ -27,11 +27,11 @@ var certPem = fs.readFileSync("test_cert.pem");
// Test signing and verifying
var s1 = (new crypto.Sign).init("RSA-SHA1").update("Test123").sign(keyPem, "base64");
var verified = !!((new crypto.Verify).init("RSA-SHA1").update("Test").update("123").verify(certPem, s1, "base64"));
-test.assertTrue(verified, "sign and verify (base 64)");
+test.ok(verified, "sign and verify (base 64)");
var s2 = (new crypto.Sign).init("RSA-SHA256").update("Test123").sign(keyPem); // binary
var verified = !!((new crypto.Verify).init("RSA-SHA256").update("Test").update("123").verify(certPem, s2)); // binary
-test.assertTrue(verified, "sign and verify (binary)");
+test.ok(verified, "sign and verify (binary)");
// Test encryption and decryption
var plaintext="Keep this a secret? No! Tell everyone about node.js!";
@@ -43,7 +43,7 @@'hex'); // Only use binary or hex, not base64.
var decipher=(new crypto.Decipher).init("aes192", "MySecretKey123");
var txt = decipher.update(ciph, 'hex', 'utf8');
txt +='utf8');
-test.assertEquals(txt, plaintext, "encryption and decryption");
+test.equal(txt, plaintext, "encryption and decryption");
// Test encyrption and decryption with explicit key and iv
var encryption_key='0123456789abcd0123456789';
@@ -57,4 +57,4 @@'hex');
var decipher=(new crypto.Decipher).initiv("des-ede3-cbc",encryption_key,iv);
var txt = decipher.update(ciph, 'hex', 'utf8');
txt +='utf8');
-test.assertEquals(txt, plaintext, "encryption and decryption with key and iv");
+test.equal(txt, plaintext, "encryption and decryption with key and iv");
Something went wrong with that request. Please try again.