Giter Site home page Giter Site logo

Comments (9)

cjerdonek avatar cjerdonek commented on May 30, 2024

By the way, a related question is whether the high and low surrogate code points in the BMP are handled correctly:

The High Surrogates (U+D800–U+DBFF) and Low Surrogate (U+DC00–U+DFFF) codes are reserved for encoding non-BMP characters in UTF-16 by using a pair of 16-bit codes: one High Surrogate and one Low Surrogate. A single surrogate code point will never be assigned a character.

Are there any test cases for these code points?

from jssha.

cjerdonek avatar cjerdonek commented on May 30, 2024

Okay, here is a test case using a non-BMP Unicode character. The test case is for SHA-256 using the default encoding UTF8. Sample Javascript code looks like the following:

// With 'TEXT', the jsSHA constructor defaults to encoding 'UTF8'.
var shaObj = new jsSHA(s, 'TEXT');
return shaObj.getHash('SHA-256', 'HEX');

When I try the string '\ud83d\ude00', which is the Unicode Character 'GRINNING FACE' (U+1F600), I get the following:

ea645893a930e0872284cf8fbc8d14f66f052aea0bc8d9c4829f08a38219940c

But I believe one should instead get:

f0443a342c5ef54783a111b51ba56c938e474c32324d90c3a60c9c8e3a37e2d9

Here is Python code I used to get the expected value (tested with Python 2.7.6):

import hashlib
import json

def sha(bytes):
    return hashlib.sha256(bytes).hexdigest()

def test(u):
    print(json.dumps(u))
    b = u.encode('utf-8')
    print(repr(b))
    print(sha(b))
    print

# Unicode Character 'GRINNING FACE' (U+1F600)
# http://www.fileformat.info/info/unicode/char/1F600/index.htm
test(u"\U0001F600")
# Gives:
# JSON:    "\ud83d\ude00"
# UTF-8:   '\xf0\x9f\x98\x80'
# SHA-256: f0443a342c5ef54783a111b51ba56c938e474c32324d90c3a60c9c8e3a37e2d9

from jssha.

cjerdonek avatar cjerdonek commented on May 30, 2024

Any acknowledgment of this issue?

I don't think it would be too hard to fix. The Mozilla page linked in the original comment has code that can probably be used close to as is.

from jssha.

Caligatio avatar Caligatio commented on May 30, 2024

Sorry for the delay here; I have had limited computer access for the last
few weeks. I found a code snippet that should fit in nicely with my string
parsing but haven't had a chance to actually try it. If you have a patch
handy, that would speed things up.

On Tuesday, September 23, 2014, Chris Jerdonek [email protected]
wrote:

Any acknowledgment of this issue?

I don't think it would be too hard to fix. The Mozilla page linked in the
original comment has code that can probably be used close to as is.


Reply to this email directly or view it on GitHub
#21 (comment).

from jssha.

cjerdonek avatar cjerdonek commented on May 30, 2024

Thanks, @Caligatio. If you already have something in mind, I'll let you take care of it. There's no rush (at least for me). I just wasn't sure if you had seen the issue.

from jssha.

Caligatio avatar Caligatio commented on May 30, 2024

I believe this should be fixed in https://github.com/Caligatio/jsSHA/blob/db68ec213c17f34eb105e9561b55045c0f7cbc65/src/sha_dev.js

Can you try out your tests to see if you come to the same conclusion?

from jssha.

cjerdonek avatar cjerdonek commented on May 30, 2024

Thanks! But can you make it easier to test? sha_dev.js is ignored in your bower.json, so I don't get the change when I bower install. Or else you could recompile the other files. Thanks.

from jssha.

Caligatio avatar Caligatio commented on May 30, 2024

All files should now be synced up.

from jssha.

cjerdonek avatar cjerdonek commented on May 30, 2024

I just had one test for this case, but it passes now. Thanks!

from jssha.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.