Skip to content

Commit

Permalink
modularize format
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Jan 28, 2015
1 parent 5091f2e commit d2a3f77
Show file tree
Hide file tree
Showing 9 changed files with 507 additions and 481 deletions.
28 changes: 14 additions & 14 deletions algos.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,69 @@ exports['RSA-SHA224'] = exports.sha224WithRSAEncryption = {
sign: 'rsa',
hash: 'sha224',
id: new Buffer('302d300d06096086480165030402040500041c', 'hex')
};
}
exports['RSA-SHA256'] = exports.sha256WithRSAEncryption = {
sign: 'rsa',
hash: 'sha256',
id: new Buffer('3031300d060960864801650304020105000420', 'hex')
};
}
exports['RSA-SHA384'] = exports.sha384WithRSAEncryption = {
sign: 'rsa',
hash: 'sha384',
id: new Buffer('3041300d060960864801650304020205000430', 'hex')
};
}
exports['RSA-SHA512'] = exports.sha512WithRSAEncryption = {
sign: 'rsa',
hash: 'sha512',
id: new Buffer('3051300d060960864801650304020305000440', 'hex')
};
}
exports['RSA-SHA1'] = {
sign: 'rsa',
hash: 'sha1',
id: new Buffer('3021300906052b0e03021a05000414', 'hex')
};
}
exports['ecdsa-with-SHA1'] = {
sign: 'ecdsa',
hash: 'sha1',
id: new Buffer('', 'hex')
};
}
exports.DSA = exports['DSA-SHA1'] = exports['DSA-SHA'] = {
sign: 'dsa',
hash: 'sha1',
id: new Buffer('', 'hex')
};
}
exports['DSA-SHA224'] = exports['DSA-WITH-SHA224'] = {
sign: 'dsa',
hash: 'sha224',
id: new Buffer('', 'hex')
};
}
exports['DSA-SHA256'] = exports['DSA-WITH-SHA256'] = {
sign: 'dsa',
hash: 'sha256',
id: new Buffer('', 'hex')
};
}
exports['DSA-SHA384'] = exports['DSA-WITH-SHA384'] = {
sign: 'dsa',
hash: 'sha384',
id: new Buffer('', 'hex')
};
}
exports['DSA-SHA512'] = exports['DSA-WITH-SHA512'] = {
sign: 'dsa',
hash: 'sha512',
id: new Buffer('', 'hex')
};
}
exports['DSA-RIPEMD160'] = {
sign: 'dsa',
hash: 'rmd160',
id: new Buffer('', 'hex')
};
}
exports['RSA-RIPEMD160'] = exports.ripemd160WithRSA = {
sign: 'rsa',
hash: 'rmd160',
id: new Buffer('3021300906052b2403020105000414', 'hex')
};
}
exports['RSA-MD5'] = exports.md5WithRSAEncryption = {
sign: 'rsa',
hash: 'md5',
id: new Buffer('3020300c06082a864886f70d020505000410', 'hex')
};
}
91 changes: 91 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use strict'
var sign = require('./sign')
var verify = require('./verify')
var stream = require('stream')
var inherits = require('inherits')
var _algos = require('./algos')
var createHash = require('create-hash')
var algos = {}
Object.keys(_algos).forEach(function (key) {
algos[key] = algos[key.toLowerCase()] = _algos[key]
})

exports.createSign = exports.Sign = createSign

function createSign (algorithm) {
return new Sign(algorithm)
}

exports.createVerify = exports.Verify = createVerify

function createVerify (algorithm) {
return new Verify(algorithm)
}

inherits(Sign, stream.Writable)

function Sign (algorithm) {
stream.Writable.call(this)
var data = algos[algorithm]
if (!data)
throw new Error('Unknown message digest')

this._hashType = data.hash
this._hash = createHash(data.hash)
this._tag = data.id
}

Sign.prototype._write = function _write (data, _, done) {
this._hash.update(data)
done()
}

Sign.prototype.update = function update (data, enc) {
if (typeof data === 'string')
data = new Buffer(data, enc)
this._hash.update(data)
return this
}

Sign.prototype.sign = function signMethod (key, enc) {
this.end()
var hash = this._hash.digest()
var sig = sign(Buffer.concat([this._tag, hash]), key, this._hashType)
if (enc) {
sig = sig.toString(enc)
}
return sig
}

inherits(Verify, stream.Writable)
function Verify (algorithm) {
stream.Writable.call(this)
var data = algos[algorithm]
if (!data)
throw new Error('Unknown message digest')

this._hash = createHash(data.hash)
this._tag = data.id
}

Verify.prototype._write = function _write (data, _, done) {
this._hash.update(data)
done()
}

Verify.prototype.update = function update (data, enc) {
if (typeof data === 'string')
data = new Buffer(data, enc)

this._hash.update(data)
return this
}

Verify.prototype.verify = function verifyMethod (key, sig, enc) {
this.end()
var hash = this._hash.digest()
if (typeof sic === 'string')
sig = new Buffer(sig, enc)

return verify(sig, Buffer.concat([this._tag, hash]), key)
}
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
require('./inject')(module.exports, require('crypto'));
var crypto = require('crypto')

exports.createSign = crypto.createSign
exports.Sign = crypto.Sign

exports.createVerify = crypto.createVerify
exports.Verify = crypto.Verify
79 changes: 0 additions & 79 deletions inject.js

This file was deleted.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
"version": "2.8.0",
"description": "",
"main": "index.js",
"browser": "browser.js",
"scripts": {
"test": "node test/index.js | tspec"
},
"repository": {
"type": "git",
"url": "git://github.com/calvinmetcalf/browserify-sign.git"
"url": "git://github.com/crypto-browserify/browserify-sign.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"bn.js": "^1.0.0",
"browserify-rsa": "^1.1.0",
"browserify-rsa": "^2.0.0",
"create-hash": "^1.1.0",
"create-hmac": "^1.1.2",
"elliptic": "^1.0.0",
"inherits": "^2.0.1",
"parse-asn1": "^2.0.0"
"parse-asn1": "^3.0.0"
},
"devDependencies": {
"tap-spec": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
browserify-sign [![Build Status](https://travis-ci.org/calvinmetcalf/browserify-sign.svg)](https://travis-ci.org/calvinmetcalf/browserify-sign)
browserify-sign [![Build Status](https://travis-ci.org/crypto-browserify/browserify-sign.svg)](https://travis-ci.org/crypto-browserify/browserify-sign)
===

a package to duplicate the functionality of node's crypto public key functions, much of this is based on [Fedor Indutny's](https://github.com/indutny) work on [tls.js](https://github.com/indutny/tls.js).
Expand Down
Loading

0 comments on commit d2a3f77

Please sign in to comment.