Skip to content

Commit d2a3f77

Browse files
committed
modularize format
1 parent 5091f2e commit d2a3f77

File tree

9 files changed

+507
-481
lines changed

9 files changed

+507
-481
lines changed

algos.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,69 @@ exports['RSA-SHA224'] = exports.sha224WithRSAEncryption = {
22
sign: 'rsa',
33
hash: 'sha224',
44
id: new Buffer('302d300d06096086480165030402040500041c', 'hex')
5-
};
5+
}
66
exports['RSA-SHA256'] = exports.sha256WithRSAEncryption = {
77
sign: 'rsa',
88
hash: 'sha256',
99
id: new Buffer('3031300d060960864801650304020105000420', 'hex')
10-
};
10+
}
1111
exports['RSA-SHA384'] = exports.sha384WithRSAEncryption = {
1212
sign: 'rsa',
1313
hash: 'sha384',
1414
id: new Buffer('3041300d060960864801650304020205000430', 'hex')
15-
};
15+
}
1616
exports['RSA-SHA512'] = exports.sha512WithRSAEncryption = {
1717
sign: 'rsa',
1818
hash: 'sha512',
1919
id: new Buffer('3051300d060960864801650304020305000440', 'hex')
20-
};
20+
}
2121
exports['RSA-SHA1'] = {
2222
sign: 'rsa',
2323
hash: 'sha1',
2424
id: new Buffer('3021300906052b0e03021a05000414', 'hex')
25-
};
25+
}
2626
exports['ecdsa-with-SHA1'] = {
2727
sign: 'ecdsa',
2828
hash: 'sha1',
2929
id: new Buffer('', 'hex')
30-
};
30+
}
3131
exports.DSA = exports['DSA-SHA1'] = exports['DSA-SHA'] = {
3232
sign: 'dsa',
3333
hash: 'sha1',
3434
id: new Buffer('', 'hex')
35-
};
35+
}
3636
exports['DSA-SHA224'] = exports['DSA-WITH-SHA224'] = {
3737
sign: 'dsa',
3838
hash: 'sha224',
3939
id: new Buffer('', 'hex')
40-
};
40+
}
4141
exports['DSA-SHA256'] = exports['DSA-WITH-SHA256'] = {
4242
sign: 'dsa',
4343
hash: 'sha256',
4444
id: new Buffer('', 'hex')
45-
};
45+
}
4646
exports['DSA-SHA384'] = exports['DSA-WITH-SHA384'] = {
4747
sign: 'dsa',
4848
hash: 'sha384',
4949
id: new Buffer('', 'hex')
50-
};
50+
}
5151
exports['DSA-SHA512'] = exports['DSA-WITH-SHA512'] = {
5252
sign: 'dsa',
5353
hash: 'sha512',
5454
id: new Buffer('', 'hex')
55-
};
55+
}
5656
exports['DSA-RIPEMD160'] = {
5757
sign: 'dsa',
5858
hash: 'rmd160',
5959
id: new Buffer('', 'hex')
60-
};
60+
}
6161
exports['RSA-RIPEMD160'] = exports.ripemd160WithRSA = {
6262
sign: 'rsa',
6363
hash: 'rmd160',
6464
id: new Buffer('3021300906052b2403020105000414', 'hex')
65-
};
65+
}
6666
exports['RSA-MD5'] = exports.md5WithRSAEncryption = {
6767
sign: 'rsa',
6868
hash: 'md5',
6969
id: new Buffer('3020300c06082a864886f70d020505000410', 'hex')
70-
};
70+
}

browser.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use strict'
2+
var sign = require('./sign')
3+
var verify = require('./verify')
4+
var stream = require('stream')
5+
var inherits = require('inherits')
6+
var _algos = require('./algos')
7+
var createHash = require('create-hash')
8+
var algos = {}
9+
Object.keys(_algos).forEach(function (key) {
10+
algos[key] = algos[key.toLowerCase()] = _algos[key]
11+
})
12+
13+
exports.createSign = exports.Sign = createSign
14+
15+
function createSign (algorithm) {
16+
return new Sign(algorithm)
17+
}
18+
19+
exports.createVerify = exports.Verify = createVerify
20+
21+
function createVerify (algorithm) {
22+
return new Verify(algorithm)
23+
}
24+
25+
inherits(Sign, stream.Writable)
26+
27+
function Sign (algorithm) {
28+
stream.Writable.call(this)
29+
var data = algos[algorithm]
30+
if (!data)
31+
throw new Error('Unknown message digest')
32+
33+
this._hashType = data.hash
34+
this._hash = createHash(data.hash)
35+
this._tag = data.id
36+
}
37+
38+
Sign.prototype._write = function _write (data, _, done) {
39+
this._hash.update(data)
40+
done()
41+
}
42+
43+
Sign.prototype.update = function update (data, enc) {
44+
if (typeof data === 'string')
45+
data = new Buffer(data, enc)
46+
this._hash.update(data)
47+
return this
48+
}
49+
50+
Sign.prototype.sign = function signMethod (key, enc) {
51+
this.end()
52+
var hash = this._hash.digest()
53+
var sig = sign(Buffer.concat([this._tag, hash]), key, this._hashType)
54+
if (enc) {
55+
sig = sig.toString(enc)
56+
}
57+
return sig
58+
}
59+
60+
inherits(Verify, stream.Writable)
61+
function Verify (algorithm) {
62+
stream.Writable.call(this)
63+
var data = algos[algorithm]
64+
if (!data)
65+
throw new Error('Unknown message digest')
66+
67+
this._hash = createHash(data.hash)
68+
this._tag = data.id
69+
}
70+
71+
Verify.prototype._write = function _write (data, _, done) {
72+
this._hash.update(data)
73+
done()
74+
}
75+
76+
Verify.prototype.update = function update (data, enc) {
77+
if (typeof data === 'string')
78+
data = new Buffer(data, enc)
79+
80+
this._hash.update(data)
81+
return this
82+
}
83+
84+
Verify.prototype.verify = function verifyMethod (key, sig, enc) {
85+
this.end()
86+
var hash = this._hash.digest()
87+
if (typeof sic === 'string')
88+
sig = new Buffer(sig, enc)
89+
90+
return verify(sig, Buffer.concat([this._tag, hash]), key)
91+
}

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
require('./inject')(module.exports, require('crypto'));
1+
var crypto = require('crypto')
2+
3+
exports.createSign = crypto.createSign
4+
exports.Sign = crypto.Sign
5+
6+
exports.createVerify = crypto.createVerify
7+
exports.Verify = crypto.Verify

inject.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33
"version": "2.8.0",
44
"description": "",
55
"main": "index.js",
6+
"browser": "browser.js",
67
"scripts": {
78
"test": "node test/index.js | tspec"
89
},
910
"repository": {
1011
"type": "git",
11-
"url": "git://github.com/calvinmetcalf/browserify-sign.git"
12+
"url": "git://github.com/crypto-browserify/browserify-sign.git"
1213
},
1314
"author": "",
1415
"license": "ISC",
1516
"dependencies": {
1617
"bn.js": "^1.0.0",
17-
"browserify-rsa": "^1.1.0",
18+
"browserify-rsa": "^2.0.0",
19+
"create-hash": "^1.1.0",
20+
"create-hmac": "^1.1.2",
1821
"elliptic": "^1.0.0",
1922
"inherits": "^2.0.1",
20-
"parse-asn1": "^2.0.0"
23+
"parse-asn1": "^3.0.0"
2124
},
2225
"devDependencies": {
2326
"tap-spec": "^1.0.1",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
browserify-sign [![Build Status](https://travis-ci.org/calvinmetcalf/browserify-sign.svg)](https://travis-ci.org/calvinmetcalf/browserify-sign)
1+
browserify-sign [![Build Status](https://travis-ci.org/crypto-browserify/browserify-sign.svg)](https://travis-ci.org/crypto-browserify/browserify-sign)
22
===
33

44
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).

0 commit comments

Comments
 (0)