Skip to content

Commit

Permalink
Merge pull request #5 from dignifiedquire/aegir
Browse files Browse the repository at this point in the history
refactor: use aegir
  • Loading branch information
daviddias committed Apr 16, 2016
2 parents e6ebef8 + fd051db commit 9c07c22
Show file tree
Hide file tree
Showing 20 changed files with 512 additions and 347 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

lib
dist
29 changes: 29 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

test
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sudo: false
language: node_js
node_js:
- 4
- 5

# Make sure we have new NPM.
before_install:
- npm install -g npm

script:
- npm run lint
- npm test
- npm run coverage

addons:
firefox: 'latest'

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish
1 change: 0 additions & 1 deletion .zuul.yml

This file was deleted.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
webcrypto
=========

> WebCryptoAPI polyfil to work in Node.js in the Browser (so that you don't have to be concerned about moving crypto code between a browser and server side app)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Coverage Status](https://coveralls.io/repos/github/diasdavid/webcrypto/badge.svg?branch=master)](https://coveralls.io/github/diasdavid/webcrypto?branch=master)
[![Travis CI](https://travis-ci.org/diasdavid/webcrypto.svg?branch=master)](https://travis-ci.org/diasdavid/webcrypto)
[![Circle CI](https://circleci.com/gh/diasdavid/webcrypto.svg?style=svg)](https://circleci.com/gh/diasdavid/webcrypto)
[![Dependency Status](https://david-dm.org/diasdavid/webcrypto.svg?style=flat-square)](https://david-dm.org/diasdavid/webcrypto) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)

> WebCryptoAPI polyfil to work in Node.js in the Browser (so that you don't have to be concerned about moving crypto code between a browser and server side app)
## Roadmap

Expand Down
12 changes: 12 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
machine:
node:
version: stable

dependencies:
pre:
- google-chrome --version
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
- sudo apt-get update
- sudo apt-get --only-upgrade install google-chrome-stable
- google-chrome --version
33 changes: 20 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@
"name": "webcrypto",
"version": "0.1.0",
"description": "Use the Node.js crypto module API without having to worry if it is being run in browser or Node.js",
"main": "src/index.js",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"test:node": "node test",
"lint": "./node_modules/.bin/standard",
"test:browser": "./node_modules/.bin/zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- test/index.js",
"test:browser:q": "BROWSER_VERSION=46 BROWSER_NAME=chrome npm run test:browser"
"lint": "aegir-lint",
"test": "aegir-test",
"test:node": "aegir-test node",
"test:browser": "aegir-test browser",
"build": "aegir-build",
"release": "aegir-release",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish"
},
"repository": {
"type": "git",
"url": "git+https://github.com/diasdavid/webcrypto.git"
},
"pre-commit": [
"lint",
"test"
],
"keywords": [
"crypto"
],
Expand All @@ -23,16 +32,14 @@
},
"homepage": "https://github.com/diasdavid/webcrypto#readme",
"dependencies": {
"crypto-browserify": "^3.10.0"
"crypto-browserify": "^3.10.0",
"detect-node": "^2.0.3"
},
"devDependencies": {
"aegir": "^2.1.1",
"chai": "^3.5.0",
"hash-test-vectors": "^1.3.2",
"pseudorandombytes": "^2.0.0",
"standard": "^5.3.1",
"tape": "^4.2.2",
"zuul": "^3.7.2"
},
"browser": {
"crypto": false
"pre-commit": "^1.1.2",
"pseudorandombytes": "^2.0.0"
}
}
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var isNode = !global.window
'use strict'

const isNode = require('detect-node')

if (isNode) {
module.exports = require('crypto')
Expand Down
53 changes: 29 additions & 24 deletions test/aes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
var test = require('tape')
var crypto = require('../src')
/* eslint-env mocha */
'use strict'

var expect = require('chai').expect
var randomBytes = require('pseudorandombytes')
var crypto = require('../src')

function runIt (i) {
/*
crypto.listCiphers().forEach(function (cipher) {
test('run: ' + i, function (t) {
t.test('ciphers: ' + cipher, function (t) {
t.plan(1)
describe('run: ' + i, function () {
it('ciphers: ' + cipher, function () {
var data = randomBytes(562)
var password = randomBytes(20)
var crypter = crypto.createCipher(cipher, password)
Expand All @@ -19,7 +21,7 @@ function runIt (i) {
decrypter.setAuthTag(crypter.getAuthTag())
}
out.push(decrypter.final())
t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'))
expect(data.toString('hex')).to.be.eql(, Buffer.concat(out).toString('hex'))
})
})
})
Expand All @@ -29,23 +31,26 @@ function runIt (i) {
*/
}
runIt(1)
test('getCiphers', function (t) {
t.plan(1)
t.ok(crypto.getCiphers().length, 'get ciphers returns an array')
})
describe('aes', function () {
it('getCiphers', function () {
expect(crypto.getCiphers()).to.not.be.empty
})

test('through crypto browserify works', function (t) {
t.plan(2)
var crypto = require('../')
var cipher = 'aes-128-ctr'
var data = randomBytes(562)
var password = randomBytes(20)
var crypter = crypto.createCipher(cipher, password)
var decrypter = crypto.createDecipher(cipher, password)
var out = []
out.push(decrypter.update(crypter.update(data)))
out.push(decrypter.update(crypter.final()))
out.push(decrypter.final())
t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'))
t.ok(crypto.getCiphers().length, 'get ciphers returns an array')
it('through crypto browserify works', function () {
var cipher = 'aes-128-ctr'
var data = randomBytes(562)
var password = randomBytes(20)
var crypter = crypto.createCipher(cipher, password)
var decrypter = crypto.createDecipher(cipher, password)
var out = []
out.push(decrypter.update(crypter.update(data)))
out.push(decrypter.update(crypter.final()))
out.push(decrypter.final())
expect(
data.toString('hex')
).to.be.eql(
Buffer.concat(out).toString('hex')
)
expect(crypto.getCiphers()).to.not.be.empty
})
})
16 changes: 11 additions & 5 deletions test/index.js → test/browser.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
'use strict'

require('./create-hash')
require('./create-hmac')
if (!process.browser) {
require('./dh')
}
require('./dh')

require('./pbkdf2')

var secure = true
try {
require('randombytes')(8)
} catch (e) {
secure = false
console.log('no secure rng available')
}

if (secure) {
require('./ecdh')
require('./public-encrypt')
require('./random-bytes')
require('./sign')
} catch (e) {
console.log('no secure rng avaiable')
}

require('./aes')
79 changes: 39 additions & 40 deletions test/create-hash.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
var test = require('tape')
/* eslint-env mocha */
'use strict'

var expect = require('chai').expect
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']
var encodings = ['hex', 'base64'] // FIXME: test binary
var vectors = require('hash-test-vectors')

testLib('createHash in crypto-browserify', require('../src').createHash)
describe('createHash', function () {
testLib('in crypto-browserify', require('../src').createHash)

function testLib (name, createHash) {
algorithms.forEach(function (algorithm) {
runTest(name, createHash, algorithm)
})
}
function testLib (name, createHash) {
algorithms.forEach(function (algorithm) {
runTest(name, createHash, algorithm)
})
}

function runTest (name, createHash, algorithm) {
test(name + ' test ' + algorithm + ' against test vectors', function (t) {
run(0)
function run (i) {
if (i >= vectors.length) {
return t.end()
}
var obj = vectors[i]

var input = new Buffer(obj.input, 'base64')
var node = obj[algorithm]
var js = createHash(algorithm).update(input).digest('hex')
if (js !== node) {
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node)
}
function runTest (name, createHash, algorithm) {
it(name + ' test ' + algorithm + ' against test vectors', function (done) {
run(0)
function run (i) {
if (i >= vectors.length) {
return done()
}
var obj = vectors[i]

encodings.forEach(function (encoding) {
var input = new Buffer(obj.input, 'base64').toString(encoding)
var input = new Buffer(obj.input, 'base64')
var node = obj[algorithm]
var js = createHash(algorithm).update(input, encoding).digest('hex')
if (js !== node) {
t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node)
}
})
input = new Buffer(obj.input, 'base64')
node = obj[algorithm]
var hash = createHash(algorithm)
hash.end(input)
js = hash.read().toString('hex')
if (js !== node) {
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node)
var js = createHash(algorithm).update(input).digest('hex')
expect(js).to.be.eql(node)

encodings.forEach(function (encoding) {
var input = new Buffer(obj.input, 'base64').toString(encoding)
var node = obj[algorithm]
var js = createHash(algorithm).update(input, encoding).digest('hex')
expect(js).to.be.eql(node)
})
input = new Buffer(obj.input, 'base64')
node = obj[algorithm]
var hash = createHash(algorithm)
hash.end(input)
js = hash.read().toString('hex')
expect(js).to.be.eql(node)

setTimeout(run, 0, i + 1)
}
setTimeout(run, 0, i + 1)
}
})
}
})
}
})
Loading

0 comments on commit 9c07c22

Please sign in to comment.