exports.Credentials = Credentials;
-function addNewline(buf) {
- var last = buf[buf.length - 1];
- var isBuf = Buffer.isBuffer(buf);
-
- if (!isBuf && !util.isString(buf))
- throw new Error('Certificate should be of type Buffer or string');
-
- if (isBuf ? last !== 10 : last !== '\n')
- return buf.toString().trim() + '\n';
- else
- return buf;
-}
exports.createCredentials = function(options, context) {
if (!options) options = {};
if (context) return c;
if (options.key) {
- var key = addNewline(options.key);
if (options.passphrase) {
- c.context.setKey(key, options.passphrase);
+ c.context.setKey(options.key, options.passphrase);
} else {
- c.context.setKey(key);
+ c.context.setKey(options.key);
}
}
- if (options.cert) c.context.setCert(addNewline(options.cert));
+ if (options.cert) c.context.setCert(options.cert);
if (options.ciphers) c.context.setCiphers(options.ciphers);
int i = nbio->IndexOf('\n', size);
- // Include '\n'
- if (i < size)
+ // Include '\n', if it's there. If not, don't read off the end.
+ if (i < size && i >= 0 && static_cast<size_t>(i) < nbio->Length())
i++;
// Shift `i` a bit to NULL-terminate string later