@trenskow/signed-stream 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/sign-stream.js +18 -4
- package/lib/verify-stream.js +20 -3
- package/package.json +1 -1
package/lib/sign-stream.js
CHANGED
|
@@ -12,12 +12,13 @@ import CryptoStream from './crypto-stream.js';
|
|
|
12
12
|
|
|
13
13
|
export default class SignStream extends CryptoStream {
|
|
14
14
|
|
|
15
|
-
constructor({ algorithm, privateKey }) {
|
|
15
|
+
constructor({ algorithm, privateKey, errorFactory }) {
|
|
16
16
|
|
|
17
17
|
const sign = createSign(algorithm);
|
|
18
18
|
|
|
19
19
|
super({
|
|
20
|
-
digester: sign
|
|
20
|
+
digester: sign,
|
|
21
|
+
errorFactory
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
this._sign = sign;
|
|
@@ -26,9 +27,22 @@ export default class SignStream extends CryptoStream {
|
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
_final(callback) {
|
|
29
|
-
super._final(
|
|
30
|
+
super._final(() => {
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
let result;
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
result = this._sign.sign(this._privateKey);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
this._reject(error);
|
|
38
|
+
return callback(error);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this._resolve(result);
|
|
42
|
+
|
|
43
|
+
callback();
|
|
44
|
+
|
|
45
|
+
});
|
|
32
46
|
|
|
33
47
|
}
|
|
34
48
|
|
package/lib/verify-stream.js
CHANGED
|
@@ -12,7 +12,7 @@ import CryptoStream from './crypto-stream.js';
|
|
|
12
12
|
|
|
13
13
|
export default class VerifyStream extends CryptoStream {
|
|
14
14
|
|
|
15
|
-
constructor({ algorithm, publicKey, signature, encoding }) {
|
|
15
|
+
constructor({ algorithm, publicKey, signature, encoding, errorFactory }) {
|
|
16
16
|
|
|
17
17
|
const verify = createVerify(algorithm);
|
|
18
18
|
|
|
@@ -23,14 +23,31 @@ export default class VerifyStream extends CryptoStream {
|
|
|
23
23
|
this._verify = verify;
|
|
24
24
|
this._publicKey = publicKey;
|
|
25
25
|
this._signature = Buffer.from(signature, encoding);
|
|
26
|
+
this._errorFactory = errorFactory;
|
|
26
27
|
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
_final(callback) {
|
|
30
|
-
super._final(
|
|
31
|
+
super._final(() => {
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
let valid = false;
|
|
33
34
|
|
|
35
|
+
try {
|
|
36
|
+
valid = this._verify.verify(this._publicKey, this._signature);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
this._reject(error);
|
|
39
|
+
return callback(error);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this._resolve(valid);
|
|
43
|
+
|
|
44
|
+
if (this.errorFactory) {
|
|
45
|
+
callback(this.errorFactory());
|
|
46
|
+
} else {
|
|
47
|
+
callback();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
});
|
|
34
51
|
}
|
|
35
52
|
|
|
36
53
|
valid() {
|