diff options
author | hogelog | 2009-01-16 22:48:10 +0000 |
---|---|---|
committer | hogelog | 2009-01-16 22:48:10 +0000 |
commit | 424b97b165e080b4a912fef8b4147bcea69cf1d4 (patch) | |
tree | aefe787a8b4b848eea6eadc99c30b8aca7a0ed92 /hash.js | |
parent | bebb561a9138021dca33e1b069267622880eafd4 (diff) | |
download | vimperator-plugins-424b97b165e080b4a912fef8b4147bcea69cf1d4.tar.bz2 |
* createInstance(nsICryptoHash) once
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@28533 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'hash.js')
-rw-r--r-- | hash.js | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -4,7 +4,7 @@ var PLUGIN_INFO = <name>{NAME}</name> <description>hash of file</description> <author mail="konbu.komuro@gmail.com" homepage="http://d.hatena.ne.jp/hogelog/">hogelog</author> - <version>0.1</version> + <version>0.2</version> <minVersion>2.0pre</minVersion> <maxVersion>2.0pre</maxVersion> <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/hash.js</updateURL> @@ -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(""); |