Skip to content
Browse files

posix has been renamed to fs; tests are using mjsunit now.

  • Loading branch information...
1 parent c7a2526 commit ae8d97c571f26d49901cd21677cbe1cbf5ca5244 @greut greut committed Feb 20, 2010
Showing with 12 additions and 17 deletions.
  1. +12 −17 test.js
29 test.js
@@ -1,65 +1,60 @@
var crypto=require("./crypto");
var sys=require("sys");
-var posix=require('posix');
+var fs=require("fs");
+var test=require("mjsunit");
// 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 hashing
var a0 = (new crypto.Hash).init("sha1").update("Test123").digest("hex");
var a1 = (new crypto.Hash).init("md5").update("Test123").digest("binary");
var a2= (new crypto.Hash).init("sha256").update("Test123").digest("base64");
var a3 = (new crypto.Hash).init("sha512").update("Test123").digest(); // binary
-sys.puts((new crypto.Hash).init("ripemd160").update("Nobody inspects the spammish repetition").digest("hex"));
// 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");
// Load our public and private keys
-var keyPem ="test_key.pem").wait();
-var certPem ="test_cert.pem").wait();
+var keyPem = fs.readFileSync("test_key.pem");
+var certPem = fs.readFileSync("test_cert.pem");
// Test signing and verifying
var s1 = (new crypto.Sign).init("RSA-SHA1").update("Test123").sign(keyPem, "base64");
-sys.puts((new crypto.Verify).init("RSA-SHA1").update("Test").update("123").verify(certPem, s1, "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)");
var s2 = (new crypto.Sign).init("RSA-SHA256").update("Test123").sign(keyPem); // binary
-sys.puts((new crypto.Verify).init("RSA-SHA256").update("Test").update("123").verify(certPem, s2)); // 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 encryption and decryption
var plaintext="Keep this a secret? No! Tell everyone about node.js!";
var cipher=(new crypto.Cipher).init("aes192", "MySecretKey123");
var ciph=cipher.update(plaintext, 'utf8', 'hex'); // encrypt plaintext which is in utf8 format to a ciphertext which will be in hex'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 encyrption and decryption with explicit key and iv
var encryption_key='0123456789abcd0123456789';
var iv = '12345678';
var cipher=(new crypto.Cipher).initiv("des-ede3-cbc", encryption_key, iv);
var ciph=cipher.update(plaintext, 'utf8', 'hex');'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");

0 comments on commit ae8d97c

Please sign in to comment.
Something went wrong with that request. Please try again.