| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent abbdcaa commit 3ddc88b
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,11 +64,12 @@ console.log(challenge.toString('utf8')); | |||
| 64 | 64 | // Prints: the challenge as a UTF8 string | |
| 65 | 65 | ``` | |
| 66 | 66 | ||
| 67 | - ### Certificate.exportPublicKey(spkac) | ||
| 67 | + ### Certificate.exportPublicKey(spkac[, encoding]) | ||
| 68 | 68 | <!-- YAML | |
| 69 | 69 | added: REPLACEME | |
| 70 | 70 | --> | |
| 71 | 71 | - `spkac` {string | Buffer | TypedArray | DataView} | |
| 72 | + - `encoding` {string} | ||
| 72 | 73 | - Returns {Buffer} The public key component of the `spkac` data structure, | |
| 73 | 74 | which includes a public key and a challenge. | |
| 74 | 75 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,20 +6,37 @@ const { | |||
| 6 | 6 | certVerifySpkac | |
| 7 | 7 | } = process.binding('crypto'); | |
| 8 | 8 | ||
| 9 | + const errors = require('internal/errors'); | ||
| 10 | + const { isArrayBufferView } = require('internal/util/types'); | ||
| 11 | + | ||
| 9 | 12 | const { | |
| 10 | 13 | toBuf | |
| 11 | 14 | } = require('internal/crypto/util'); | |
| 12 | 15 | ||
| 13 | - function verifySpkac(object) { | ||
| 14 | - return certVerifySpkac(object); | ||
| 16 | + function verifySpkac(spkac) { | ||
| 17 | + if (!isArrayBufferView(spkac)) { | ||
| 18 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'spkac', | ||
| 19 | + ['Buffer', 'TypedArray', 'DataView']); | ||
| 20 | + } | ||
| 21 | + return certVerifySpkac(spkac); | ||
| 15 | 22 | } | |
| 16 | 23 | ||
| 17 | - function exportPublicKey(object, encoding) { | ||
| 18 | - return certExportPublicKey(toBuf(object, encoding)); | ||
| 24 | + function exportPublicKey(spkac, encoding) { | ||
| 25 | + spkac = toBuf(spkac, encoding); | ||
| 26 | + if (!isArrayBufferView(spkac)) { | ||
| 27 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'spkac', | ||
| 28 | + ['string', 'Buffer', 'TypedArray', 'DataView']); | ||
| 29 | + } | ||
| 30 | + return certExportPublicKey(spkac); | ||
| 19 | 31 | } | |
| 20 | 32 | ||
| 21 | - function exportChallenge(object, encoding) { | ||
| 22 | - return certExportChallenge(toBuf(object, encoding)); | ||
| 33 | + function exportChallenge(spkac, encoding) { | ||
| 34 | + spkac = toBuf(spkac, encoding); | ||
| 35 | + if (!isArrayBufferView(spkac)) { | ||
| 36 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'spkac', | ||
| 37 | + ['string', 'Buffer', 'TypedArray', 'DataView']); | ||
| 38 | + } | ||
| 39 | + return certExportChallenge(spkac); | ||
| 23 | 40 | } | |
| 24 | 41 | ||
| 25 | 42 | // For backwards compatibility reasons, this cannot be converted into a | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5816,14 +5816,8 @@ bool VerifySpkac(const char* data, unsigned int len) { | |||
| 5816 | 5816 | ||
| 5817 | 5817 | ||
| 5818 | 5818 | void VerifySpkac(const FunctionCallbackInfo<Value>& args) { | |
| 5819 | - Environment* env = Environment::GetCurrent(args); | ||
| 5820 | 5819 | bool i = false; | |
| 5821 | 5820 | ||
| 5822 | - if (args.Length() < 1) | ||
| 5823 | - return env->ThrowTypeError("Data argument is mandatory"); | ||
| 5824 | - | ||
| 5825 | - THROW_AND_RETURN_IF_NOT_BUFFER(args[0], "Data"); | ||
| 5826 | - | ||
| 5827 | 5821 | size_t length = Buffer::Length(args[0]); | |
| 5828 | 5822 | if (length == 0) | |
| 5829 | 5823 | return args.GetReturnValue().Set(i); | |
@@ -5881,11 +5875,6 @@ char* ExportPublicKey(const char* data, int len, size_t* size) { | |||
| 5881 | 5875 | void ExportPublicKey(const FunctionCallbackInfo<Value>& args) { | |
| 5882 | 5876 | Environment* env = Environment::GetCurrent(args); | |
| 5883 | 5877 | ||
| 5884 | - if (args.Length() < 1) | ||
| 5885 | - return env->ThrowTypeError("Public key argument is mandatory"); | ||
| 5886 | - | ||
| 5887 | - THROW_AND_RETURN_IF_NOT_BUFFER(args[0], "Public key"); | ||
| 5888 | - | ||
| 5889 | 5878 | size_t length = Buffer::Length(args[0]); | |
| 5890 | 5879 | if (length == 0) | |
| 5891 | 5880 | return args.GetReturnValue().SetEmptyString(); | |
@@ -5922,11 +5911,6 @@ const char* ExportChallenge(const char* data, int len) { | |||
| 5922 | 5911 | void ExportChallenge(const FunctionCallbackInfo<Value>& args) { | |
| 5923 | 5912 | Environment* env = Environment::GetCurrent(args); | |
| 5924 | 5913 | ||
| 5925 | - if (args.Length() < 1) | ||
| 5926 | - return env->ThrowTypeError("Challenge argument is mandatory"); | ||
| 5927 | - | ||
| 5928 | - THROW_AND_RETURN_IF_NOT_BUFFER(args[0], "Challenge"); | ||
| 5929 | - | ||
| 5930 | 5914 | size_t len = Buffer::Length(args[0]); | |
| 5931 | 5915 | if (len == 0) | |
| 5932 | 5916 | return args.GetReturnValue().SetEmptyString(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,3 +80,37 @@ function stripLineEndings(obj) { | |||
| 80 | 80 | ||
| 81 | 81 | // direct call Certificate() should return instance | |
| 82 | 82 | assert(Certificate() instanceof Certificate); | |
| 83 | + | ||
| 84 | + [1, {}, [], Infinity, true, 'test', undefined, null].forEach((i) => { | ||
| 85 | + common.expectsError( | ||
| 86 | + () => Certificate.verifySpkac(i), | ||
| 87 | + { | ||
| 88 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 89 | + type: TypeError, | ||
| 90 | + message: 'The "spkac" argument must be one of type Buffer, TypedArray, ' + | ||
| 91 | + 'or DataView' | ||
| 92 | + } | ||
| 93 | + ); | ||
| 94 | + }); | ||
| 95 | + | ||
| 96 | + [1, {}, [], Infinity, true, undefined, null].forEach((i) => { | ||
| 97 | + common.expectsError( | ||
| 98 | + () => Certificate.exportPublicKey(i), | ||
| 99 | + { | ||
| 100 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 101 | + type: TypeError, | ||
| 102 | + message: 'The "spkac" argument must be one of type string, Buffer,' + | ||
| 103 | + ' TypedArray, or DataView' | ||
| 104 | + } | ||
| 105 | + ); | ||
| 106 | + | ||
| 107 | + common.expectsError( | ||
| 108 | + () => Certificate.exportChallenge(i), | ||
| 109 | + { | ||
| 110 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 111 | + type: TypeError, | ||
| 112 | + message: 'The "spkac" argument must be one of type string, Buffer,' + | ||
| 113 | + ' TypedArray, or DataView' | ||
| 114 | + } | ||
| 115 | + ); | ||
| 116 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments