Skip to content

Commit 1ff17fb

Browse files
committed
Support ArrayBuffer input.
1 parent f73267a commit 1ff17fb

File tree

10 files changed

+117
-92
lines changed

10 files changed

+117
-92
lines changed

.covignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/tests/
2+
node_modules/

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
covreporter
2+
build
3+
tests

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v0.3.0 / 2015-05-23
2+
3+
* Support ArrayBuffer input.
4+
15
# v0.2.3 / 2015-02-11
26

37
* Support byte array input.

LICENSE.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Copyright 2014-2015 [email protected]
1+
Copyright (c) 2015 Chen Yi-Cyuan
2+
3+
MIT License
24

35
Permission is hereby granted, free of charge, to any person obtaining
46
a copy of this software and associated documentation files (the

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Output
6868
72726d8818f693066ceb69afa364218b692e62ea92b385782363780f47529c21
6969
dfbab71afdf54388af4d55f8bd3de8c9b15e0eb916bf9125f4a959d4
7070

71-
It also supports byte Array or Uint8Array input:
71+
It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` input:
7272

7373
Code
7474
```JavaScript

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-sha256",
3-
"version": "0.2.3",
4-
"main": ["build/sha256.min.js"],
3+
"version": "0.3.0",
4+
"main": ["src/sha256.js"],
55
"ignore": [
66
"samples",
77
"tests"

build/sha256.min.js

Lines changed: 17 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-sha256",
3-
"version": "0.2.3",
3+
"version": "0.3.0",
44
"description": "A simple SHA-256 / SHA-224 hash function for JavaScript supports UTF-8 encoding.",
55
"main": "src/sha256.js",
66
"devDependencies": {

src/sha256.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* js-sha256 v0.2.3
2+
* js-sha256 v0.3.0
33
* https://github.com/emn178/js-sha256
44
*
55
* Copyright 2014-2015, [email protected]
@@ -29,16 +29,16 @@
2929

3030
var blocks = [];
3131

32-
Array.prototype.__ARRAY__ = true;
33-
if(TYPED_ARRAY) {
34-
Uint8Array.prototype.__ARRAY__ = true;
35-
}
36-
3732
var sha224 = function(message) {
3833
return sha256(message, true);
3934
};
4035

4136
var sha256 = function(message, is224) {
37+
var notString = typeof(message) != 'string';
38+
if(notString && message.constructor == root.ArrayBuffer) {
39+
message = new Uint8Array(message);
40+
}
41+
4242
var h0, h1, h2, h3, h4, h5, h6, h7, block, code, first = true, end = false,
4343
i, j, index = 0, start = 0, bytes = 0, length = message.length,
4444
s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
@@ -69,7 +69,7 @@
6969
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
7070
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
7171
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
72-
if(message.__ARRAY__) {
72+
if(notString) {
7373
for (i = start;index < length && i < 64; ++index) {
7474
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
7575
}

0 commit comments

Comments
 (0)