1 | // Copyright 2015 Joyent, Inc.
|
---|
2 |
|
---|
3 | var assert = require('assert-plus');
|
---|
4 | var util = require('util');
|
---|
5 |
|
---|
6 | function FingerprintFormatError(fp, format) {
|
---|
7 | if (Error.captureStackTrace)
|
---|
8 | Error.captureStackTrace(this, FingerprintFormatError);
|
---|
9 | this.name = 'FingerprintFormatError';
|
---|
10 | this.fingerprint = fp;
|
---|
11 | this.format = format;
|
---|
12 | this.message = 'Fingerprint format is not supported, or is invalid: ';
|
---|
13 | if (fp !== undefined)
|
---|
14 | this.message += ' fingerprint = ' + fp;
|
---|
15 | if (format !== undefined)
|
---|
16 | this.message += ' format = ' + format;
|
---|
17 | }
|
---|
18 | util.inherits(FingerprintFormatError, Error);
|
---|
19 |
|
---|
20 | function InvalidAlgorithmError(alg) {
|
---|
21 | if (Error.captureStackTrace)
|
---|
22 | Error.captureStackTrace(this, InvalidAlgorithmError);
|
---|
23 | this.name = 'InvalidAlgorithmError';
|
---|
24 | this.algorithm = alg;
|
---|
25 | this.message = 'Algorithm "' + alg + '" is not supported';
|
---|
26 | }
|
---|
27 | util.inherits(InvalidAlgorithmError, Error);
|
---|
28 |
|
---|
29 | function KeyParseError(name, format, innerErr) {
|
---|
30 | if (Error.captureStackTrace)
|
---|
31 | Error.captureStackTrace(this, KeyParseError);
|
---|
32 | this.name = 'KeyParseError';
|
---|
33 | this.format = format;
|
---|
34 | this.keyName = name;
|
---|
35 | this.innerErr = innerErr;
|
---|
36 | this.message = 'Failed to parse ' + name + ' as a valid ' + format +
|
---|
37 | ' format key: ' + innerErr.message;
|
---|
38 | }
|
---|
39 | util.inherits(KeyParseError, Error);
|
---|
40 |
|
---|
41 | function SignatureParseError(type, format, innerErr) {
|
---|
42 | if (Error.captureStackTrace)
|
---|
43 | Error.captureStackTrace(this, SignatureParseError);
|
---|
44 | this.name = 'SignatureParseError';
|
---|
45 | this.type = type;
|
---|
46 | this.format = format;
|
---|
47 | this.innerErr = innerErr;
|
---|
48 | this.message = 'Failed to parse the given data as a ' + type +
|
---|
49 | ' signature in ' + format + ' format: ' + innerErr.message;
|
---|
50 | }
|
---|
51 | util.inherits(SignatureParseError, Error);
|
---|
52 |
|
---|
53 | function CertificateParseError(name, format, innerErr) {
|
---|
54 | if (Error.captureStackTrace)
|
---|
55 | Error.captureStackTrace(this, CertificateParseError);
|
---|
56 | this.name = 'CertificateParseError';
|
---|
57 | this.format = format;
|
---|
58 | this.certName = name;
|
---|
59 | this.innerErr = innerErr;
|
---|
60 | this.message = 'Failed to parse ' + name + ' as a valid ' + format +
|
---|
61 | ' format certificate: ' + innerErr.message;
|
---|
62 | }
|
---|
63 | util.inherits(CertificateParseError, Error);
|
---|
64 |
|
---|
65 | function KeyEncryptedError(name, format) {
|
---|
66 | if (Error.captureStackTrace)
|
---|
67 | Error.captureStackTrace(this, KeyEncryptedError);
|
---|
68 | this.name = 'KeyEncryptedError';
|
---|
69 | this.format = format;
|
---|
70 | this.keyName = name;
|
---|
71 | this.message = 'The ' + format + ' format key ' + name + ' is ' +
|
---|
72 | 'encrypted (password-protected), and no passphrase was ' +
|
---|
73 | 'provided in `options`';
|
---|
74 | }
|
---|
75 | util.inherits(KeyEncryptedError, Error);
|
---|
76 |
|
---|
77 | module.exports = {
|
---|
78 | FingerprintFormatError: FingerprintFormatError,
|
---|
79 | InvalidAlgorithmError: InvalidAlgorithmError,
|
---|
80 | KeyParseError: KeyParseError,
|
---|
81 | SignatureParseError: SignatureParseError,
|
---|
82 | KeyEncryptedError: KeyEncryptedError,
|
---|
83 | CertificateParseError: CertificateParseError
|
---|
84 | };
|
---|