[Pkg-javascript-commits] [node-ripemd160] 15/71: allow string input
Bastien Roucariès
rouca at moszumanska.debian.org
Thu May 4 10:25:38 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-ripemd160.
commit 31caa73e571d7ab0dc09ed5ab7f71d3c6e598c34
Author: JP Richardson <jprichardson at gmail.com>
Date: Sun Mar 9 11:25:56 2014 -0500
allow string input
---
CHANGELOG.md | 2 +-
README.md | 20 ++------------------
lib/ripemd160.js | 4 ++++
test/ripemd160.test.js | 7 +++++++
4 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc65121..b7c46f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@
------------------
* removed bower.json and component.json
* changed 4 spacing to 2
-* returns `Buffer` type now, input must be Array, Uint8Array, or Buffer
+* returns `Buffer` type now, input must be Array, Uint8Array, Buffer, or string
0.1.0 / 2013-11-20
------------------
diff --git a/README.md b/README.md
index 2a2483d..ce8fd28 100644
--- a/README.md
+++ b/README.md
@@ -11,32 +11,16 @@ Install
npm install --save ripemd160
-### Component
-
- component install cryptocoinjs/ripemd160
-
-
-### Bower
-
- bower install ripemd160
-
-
-### Script
-
-```html
-<script src="/path/to/ripemd160.js"></script>
-```
-
Usage
-----
### ripemd160(input)
-input either an array of bytes or a string
+Input either a string or `Buffer`. Output is a `Buffer`.
```js
-ripemd160("hello") //"108f07b8382412612c048d07d13f814118445acd"
+console.log(ripemd160("hello").toString('hex')) // => 108f07b8382412612c048d07d13f814118445acd"
```
diff --git a/lib/ripemd160.js b/lib/ripemd160.js
index df519a1..08d66d6 100644
--- a/lib/ripemd160.js
+++ b/lib/ripemd160.js
@@ -174,6 +174,10 @@ function rotl(x,n) {
function ripemd160(message) {
var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0];
+
+ if (typeof message == 'string')
+ message = new Buffer(message, 'utf8');
+
var m = bytesToWords(message);
var nBitsLeft = message.length * 8;
diff --git a/test/ripemd160.test.js b/test/ripemd160.test.js
index 99a1411..2eb89f5 100644
--- a/test/ripemd160.test.js
+++ b/test/ripemd160.test.js
@@ -5,6 +5,13 @@ require('terst')
describe('+ ripemd160(input)', function() {
describe('> when input is a string', function() {
it('should compute the ripemd160 hash', function() {
+ var input = "hello";
+ EQ (ripemd160(input).toString('hex'), "108f07b8382412612c048d07d13f814118445acd")
+ })
+ })
+
+ describe('> when input is a buffer', function() {
+ it('should compute the ripemd160 hash', function() {
var input = new Buffer("hello");
EQ (ripemd160(input).toString('hex'), "108f07b8382412612c048d07d13f814118445acd")
})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ripemd160.git
More information about the Pkg-javascript-commits
mailing list