From 424b97b165e080b4a912fef8b4147bcea69cf1d4 Mon Sep 17 00:00:00 2001 From: hogelog Date: Fri, 16 Jan 2009 22:48:10 +0000 Subject: * createInstance(nsICryptoHash) once git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@28533 d0d07461-0603-4401-acd4-de1884942a52 --- hash.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'hash.js') diff --git a/hash.js b/hash.js index 1f3422f..5f414bd 100644 --- a/hash.js +++ b/hash.js @@ -4,7 +4,7 @@ var PLUGIN_INFO = {NAME} hash of file hogelog - 0.1 + 0.2 2.0pre 2.0pre http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/hash.js @@ -19,6 +19,7 @@ hash: //}}} (function() { + const Crypt = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash); const PR_UINT_MAX = 0xffffffff; const Cc = Components.classes; const Ci = Components.interfaces; @@ -57,15 +58,15 @@ hash: let [algo, path] = args; let stream = getStream(path); - let crypt = Cc["@mozilla.org/security/hash;1"] - .createInstance(Ci.nsICryptoHash); - crypt.initWithString(algo); + Crypt.initWithString(algo); // read the entire stream - crypt.updateFromStream(stream, PR_UINT_MAX); + Crypt.updateFromStream(stream, PR_UINT_MAX); + + stream.close(); // get base-64 string - let hash = crypt.finish(false); + let hash = Crypt.finish(false); // convert the binary hash data to a hex string. let str = [toHexString(hash.charCodeAt(i)) for(i in hash)].join(""); -- cgit v1.2.3