s); const pssSaltLength = getSaltLength(options); // Options specific to (EC)DSA const dsaSigEnc = getDSASignatureEncoding(options); const ret = this[kHandle].sign(data, format, type, passphrase, rsaPadding, pssSaltLength, dsaSigEnc); encoding = encoding || getDefaultEncoding(); if (encoding && encoding !== 'buffer') return ret.toString(encoding); return ret; }; function signOneShot(algorithm, data, key, callback) { if (algorithm != null) validateString(algorithm, 'algorithm'); if (callback !== undefined) validateCallback(callback); data = getArrayBufferOrView(data, 'data'); if (!key) throw new ERR_CRYPTO_SIGN_KEY_REQUIRED(); // Options specific to RSA const rsaPadding = getPadding(key); const pssSaltLength = getSaltLength(key); // Options specific to (EC)DSA const dsaSigEnc = getDSASignatureEncoding(key); const { data: keyData, format: keyFormat, type: keyType, passphrase: keyPassphrase } = preparePrivateKey(key); const job = new SignJob( callback ? kCryptoJobAsync : kCryptoJobSync, kSignJobModeSign, keyData, keyFormat, keyType, keyPassphrase, data, algorithm, pssSaltLength, rsaPadding, dsaSigEnc); if (!callback) { const { 0: err, 1: signature } = job.run(); if (err !== undefined) throw err; return Buffer.from(signature); } job.ondone = (error, signature) => { if (error) return FunctionPrototypeCall(callback, job, error); FunctionPrototypeCall(callback, job, null, Buffer.from(signature)); }; job.run(); } function Verify(algorithm, options) { if (!(this instanceof Verify)) return new Verify(algorithm, options); validateString(algorithm, 'algorithm'); this[kHandle] = new _Verify(); this[kHandle].init(algorithm); ReflectApply(Writable, this, [options]); } ObjectSetPrototypeOf(Verify.prototype, Writable.prototype); ObjectSetPrototypeOf(Verify, Writable); Verify.prototype._write = Sign.prototype._write; Verify.prototype.update = Sign.prototype.update; Verify.prototype.verify = function verify(options, signature, sigEncoding) { const { data, format, type, passphrase } = preparePublicOrPrivateKey(options, true); sigEncoding = sigEncoding || getDefaultEncoding(); // Options specific to RSA const rsaPadding = getPadding(options); const pssSaltLength = getSaltLength(options); // Options specific to (EC)DSA const dsaSigEnc = getDSASignatureEncoding(options); signature = getArrayBufferOrView(signature, 'signature', sigEncoding); return this[kHandle].verify(data, format, type, passphrase, signature, rsaPadding, pssSaltLength, dsaSigEnc); }; function verifyOneShot(algorithm, data, key, signature, callback) { if (algorithm != null) validateString(algorithm, 'algorithm'); if (callback !== undefined) validateCallback(callback); data = getArrayBufferOrView(data, 'data'); if (!isArrayBufferView(data)) { throw new ERR_INVALID_ARG_TYPE( 'data', ['Buffer', 'TypedArray', 'DataView'], data ); } // Options specific to RSA const rsaPadding = getPadding(key); const pssSaltLength = getSaltLength(key); // Options specific to (EC)DSA const dsaSigEnc = getDSASignatureEncoding(key); if (!isArrayBufferView(signature)) { throw new ERR_INVALID_ARG_TYPE( 'signature', ['Buffer', 'TypedArray', 'DataView'], signature ); } const { data: keyData, format: keyFormat, type: keyType, passphrase: keyPassphrase } = preparePublicOrPrivateKey(key); const job = new SignJob( callback ? kCryptoJobAsync : kCryptoJobSync, kSignJobModeVerify, keyData, keyFormat, keyType, keyPassphrase, data, algorithm, pssSaltLength, rsaPadding, dsaSigEnc, signature); if (!callback) { const { 0: err, 1: result } = job.run(); if (err !== undefined) throw err; return result; } job.ondone = (error, result) => { if (error) return FunctionPrototypeCall(callback, job, error); FunctionPrototypeCall(callback, job, null, result); }; job.run(); } module.exports = { Sign, signOneShot, Verify, verifyOneShot, };