MCPcopy Index your code
hub / github.com/nodejs/node / signOneShot

Function signOneShot

lib/internal/crypto/sig.js:158–217  ·  view source on GitHub ↗
(algorithm, data, key, callback)

Source from the content-addressed store, hash-verified

156};
157
158function signOneShot(algorithm, data, key, callback) {
159 if (algorithm != null)
160 validateString(algorithm, 'algorithm');
161
162 if (callback !== undefined)
163 validateFunction(callback, 'callback');
164
165 data = getArrayBufferOrView(data, 'data');
166
167 if (!key)
168 throw new ERR_CRYPTO_SIGN_KEY_REQUIRED();
169
170 // Options specific to RSA
171 const rsaPadding = getPadding(key);
172 const pssSaltLength = getSaltLength(key);
173
174 // Options specific to (EC)DSA
175 const dsaSigEnc = getDSASignatureEncoding(key);
176
177 // Options specific to Ed448 and ML-DSA
178 const context = getContext(key);
179
180 const {
181 data: keyData,
182 format: keyFormat,
183 type: keyType,
184 passphrase: keyPassphrase,
185 namedCurve: keyNamedCurve,
186 } = preparePrivateKey(key);
187
188 const job = new SignJob(
189 callback ? kCryptoJobAsync : kCryptoJobSync,
190 kSignJobModeSign,
191 keyData,
192 keyFormat,
193 keyType,
194 keyPassphrase,
195 keyNamedCurve,
196 data,
197 algorithm,
198 pssSaltLength,
199 rsaPadding,
200 dsaSigEnc,
201 context,
202 undefined);
203
204 if (!callback) {
205 const { 0: err, 1: signature } = job.run();
206 if (err !== undefined)
207 throw err;
208
209 return Buffer.from(signature);
210 }
211
212 job.ondone = (error, signature) => {
213 if (error) return FunctionPrototypeCall(callback, job, error);
214 FunctionPrototypeCall(callback, job, null, Buffer.from(signature));
215 };

Callers

nothing calls this directly

Calls 7

getPaddingFunction · 0.85
getSaltLengthFunction · 0.85
getDSASignatureEncodingFunction · 0.85
preparePrivateKeyFunction · 0.85
getContextFunction · 0.70
runMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…