Skip to content

Commit

Permalink
Merge pull request #14 from vrza/node-12-test1
Browse files Browse the repository at this point in the history
Version 3.0.0
  • Loading branch information
vrza authored Sep 12, 2019
2 parents 0b3c2ce + 8f1ffc2 commit c5f731b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
11 changes: 1 addition & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@ os:

language: cpp

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8

env:
matrix:
- TRAVIS_NODE_VERSION="6"
- TRAVIS_NODE_VERSION="7"
- TRAVIS_NODE_VERSION="8"
- TRAVIS_NODE_VERSION="9"
- TRAVIS_NODE_VERSION="10"
- TRAVIS_NODE_VERSION="12"

install:
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi
- $CXX --version
- travis_retry npm install

Expand Down
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ SHA-1, MD5, and SHA-512 are susceptible to length-extension".
[https://blake2.net/](https://blake2.net/)

node-blake2 provides a [stream](https://nodejs.org/api/stream.html)-compatible
blake2b, blake2bp, blake2s, and blake2sp `Hash` and `KeyedHash` for node 6+.
blake2b, blake2bp, blake2s, and blake2sp `Hash` and `KeyedHash` for node 8+.

node-blake2 was tested to work on
- Ubuntu 14.04 (g++ 4.8.2)
- Ubuntu 14.04 (clang++ 3.6.2-svn238746-1~exp1)
- Ubuntu 15.04 (g++ 4.9.2)
- GNU/Linux Ubuntu 16.04 (g++ 5.4.0)
- macOS 10.13 (Apple LLVM 9.1.0)
- Windows 8.1 x64 (VS2013)
- OS X 10.10 (Apple LLVM 6.1.0)


Install
---

On Windows, first install [Python 2.7.13](https://www.python.org/downloads/release/python-2713/) so that node-gyp works.
On Windows, first install [Python 2.7.16](https://www.python.org/downloads/release/python-2716/) so that node-gyp works.

In your project, run:

Expand All @@ -34,7 +32,7 @@ npm install blake2 --save
or install from the GitHub repo:

```
npm install ludios/node-blake2 --save
npm install vrza/node-blake2 --save
```


Expand All @@ -51,7 +49,7 @@ console.log(h.digest("hex"));
```

`blake2.createHash` works like node's
[`crypto.createHash`](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm).
[`crypto.createHash`](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options).

### Keyed BLAKE2b

Expand All @@ -63,7 +61,7 @@ console.log(h.digest("hex"));
```

`blake2.createKeyedHash` takes a key argument like
[`crypto.createHmac`](https://nodejs.org/api/crypto.html#crypto_crypto_createhmac_algorithm_key).
[`crypto.createHmac`](https://nodejs.org/api/crypto.html#crypto_crypto_createhmac_algorithm_key_options).
Although it is not an HMAC, a keyed hash serves the same purpose.

### Important notes
Expand All @@ -76,7 +74,7 @@ Although it is not an HMAC, a keyed hash serves the same purpose.

### With streams

This works exactly like it does with [`crypto.Hash`](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm). See [b2sum.js](https://github.com/ludios/node-blake2/blob/master/b2sum.js).
This works exactly like it does with [`crypto.Hash`](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options). See [b2sum.js](https://github.com/vrza/node-blake2/blob/master/b2sum.js).

### Custom digest length

Expand Down Expand Up @@ -130,5 +128,5 @@ Known issues

[npm-image]: https://img.shields.io/npm/v/blake2.svg
[npm-url]: https://npmjs.org/package/blake2
[travis-image]: https://img.shields.io/travis/ludios/node-blake2.svg
[travis-url]: https://travis-ci.org/ludios/node-blake2
[travis-image]: https://img.shields.io/travis/vrza/node-blake2.svg
[travis-url]: https://travis-ci.org/vrza/node-blake2
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blake2",
"version": "2.0.2",
"version": "3.0.0",
"description": "All four BLAKE2 variants (blake2b, blake2bp, blake2s, blake2sp) for node, with stream support",
"keywords": [
"crypto",
Expand All @@ -27,12 +27,17 @@
"nan": "^2.14.0"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint": "^6.3.0",
"mocha": "^6.2.0"
},
"author": "Ivan Kozik",
"contributors": [
"Ivan Kozik <[email protected]> (https://github.com/ivan)",
"James Bowes <[email protected]> (https://github.com/jbowes)",
"Kannan Goundan <[email protected]> (https://github.com/cakoose)",
"Vladimir Vrzić <[email protected]> (https://github.com/vrza)"
],
"license": "ISC",
"engines": {
"node": ">= 6.0.0"
"node": ">= 8.0.0"
}
}
17 changes: 9 additions & 8 deletions src/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Hash: public Nan::ObjectWrap {
Nan::SetPrototypeMethod(tpl, "update", Update);
Nan::SetPrototypeMethod(tpl, "digest", Digest);
Nan::SetPrototypeMethod(tpl, "copy", Copy);
target->Set(Nan::New("Hash").ToLocalChecked(), tpl->GetFunction());
target->Set(Nan::New("Hash").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
}

static
Expand All @@ -52,7 +52,7 @@ class Hash: public Nan::ObjectWrap {
if (info.Length() < 1 || !info[0]->IsString()) {
return Nan::ThrowError(v8::Exception::TypeError(Nan::New<v8::String>("First argument must be a string with algorithm name").ToLocalChecked()));
}
std::string algo = std::string(*v8::String::Utf8Value(info[0]->ToString()));
std::string algo = std::string(*v8::String::Utf8Value(v8::Isolate::GetCurrent(), info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local<v8::String>())));

const char *key_data = nullptr;
size_t key_length;
Expand All @@ -70,7 +70,7 @@ class Hash: public Nan::ObjectWrap {
if (!info[2]->IsNumber()) {
return Nan::ThrowError(v8::Exception::TypeError(Nan::New<v8::String>("digestLength must be a number").ToLocalChecked()));
}
digest_length = info[2]->IntegerValue();
digest_length = info[2]->IntegerValue(Nan::GetCurrentContext()).ToChecked();
}
}

Expand Down Expand Up @@ -187,7 +187,7 @@ class Hash: public Nan::ObjectWrap {
return Nan::ThrowError(v8::Exception::TypeError(Nan::New<v8::String>("Bad argument; need a Buffer").ToLocalChecked()));
}

v8::Local<v8::Object> buffer_obj = info[0]->ToObject();
v8::Local<v8::Object> buffer_obj = info[0]->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
const char *buffer_data = node::Buffer::Data(buffer_obj);
size_t buffer_length = node::Buffer::Length(buffer_obj);
obj->any_blake2_update(
Expand Down Expand Up @@ -230,23 +230,24 @@ class Hash: public Nan::ObjectWrap {
const unsigned argc = 1;
v8::Local<v8::Value> argv[argc] = { Nan::New<v8::String>("bypass").ToLocalChecked() };

v8::Local<v8::Function> construct = Nan::New<v8::FunctionTemplate>(hash_constructor)->GetFunction();
v8::Local<v8::Object> inst = Nan::NewInstance(construct, argc, argv).ToLocalChecked();
v8::Local<v8::FunctionTemplate> tmpl = Nan::New<v8::FunctionTemplate>(hash_constructor);
Nan::MaybeLocal<v8::Function> construct = Nan::GetFunction(tmpl);
Nan::MaybeLocal<v8::Object> inst = Nan::NewInstance(construct.ToLocalChecked(), argc, argv).ToLocalChecked();
// Construction may fail with a JS exception, in which case we just need
// to return.
if (inst.IsEmpty()) {
return;
}
Hash *dest = new Hash();
dest->Wrap(inst);
dest->Wrap(inst.ToLocalChecked());

dest->initialized_ = src->initialized_;
dest->any_blake2_update = src->any_blake2_update;
dest->any_blake2_final = src->any_blake2_final;
dest->outbytes = src->outbytes;
dest->state = src->state;

info.GetReturnValue().Set(inst);
info.GetReturnValue().Set(inst.ToLocalChecked());
}
};

Expand Down

0 comments on commit c5f731b

Please sign in to comment.