Generating a hash for an extension - Mozilla

This is a discussion on Generating a hash for an extension - Mozilla ; Hello, I'm trying to set put the download of an extension (not my own, as my JavaScript problems indicate) as per http://developer.mozilla.org/en/docs...From_Web_Pages and am having some problems generating the hash. I installed Extension Developer and in the JavaScript Shell and ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Generating a hash for an extension

  1. Generating a hash for an extension

    Hello,
    I'm trying to set put the download of an extension (not my own, as my
    JavaScript problems indicate) as per
    http://developer.mozilla.org/en/docs...From_Web_Pages
    and am having some problems generating the hash. I installed
    Extension Developer and in the JavaScript Shell and ran the following:

    // hardcoded here for convenience
    var path = "c:\GetIt.xpi";
    var f = Components.classes["@mozilla.org/file/local;1"]
    .createInstance(Components.interfaces.nsILocalFile );
    f.initWithPath(path);
    var istream = Components.classes["@mozilla.org/network/file-input-
    stream;1"]
    .createInstance(Components.interfaces.nsIFileInput Stream);
    // open for reading
    istream.init(f, 0x01, 0444, 0);
    var ch = Components.classes["@mozilla.org/security/hash;1"]
    .createInstance(Components.interfaces.nsICryptoHas h);
    // we want to use the MD5 algorithm
    ch.init(ch.MD5);
    // this tells updateFromStream to read the entire file
    const PR_UINT32_MAX = 0xffffffff;
    ch.updateFromStream(istream, PR_UINT32_MAX);
    // pass false here to get binary data back
    var hash = ch.finish(false);

    // return the two-digit hexadecimal code for a byte
    function toHexString(charCode)
    {
    return ("0" + charCode.toString(16)).slice(-2);
    }

    // convert the binary hash data to a hex string.
    var s = [toHexString(hash.charCodeAt(i)) for (i in hash)].join("");
    // s now contains your hash in hex

    Instead of a hash value I get the following error:
    TypeError on line 15: redeclaration of const PR_UINT32_MAX

    Any help you could give would be greatly appreciated.

    Thanks,
    Patrick
    http://www.patrickwhite.org


  2. Re: Generating a hash for an extension

    On 7/18/07, mhnin0@gmail.com wrote:
    > Instead of a hash value I get the following error:
    > TypeError on line 15: redeclaration of const PR_UINT32_MAX


    Sounds like you already declared that constant in the shell you have
    open. Did you try restarting Firefox and running the code again? Also
    in what scope do you run this code in? It could have this const
    defined already.

    Nickolay

  3. Re: Generating a hash for an extension

    On 7/18/07, Patrick White wrote:
    > Here's what I did: Restart Firefox, open JavaScript Shell, paste in the
    > code, press enter.
    > The result: first time: no effect, just a new line (do I need to do
    > something to display var s?) Second time: the initially reported error.
    >


    Right. The first time your code got executed, but nothing was output,
    because you didn't ask it to. You can press "s", then Enter or submit
    "print(s)" to print the value of s.

    Nickolay

+ Reply to Thread