old-keypairs.js/lib/pem-packer.js

15 lines
376 B
JavaScript
Raw Normal View History

2018-12-18 04:08:46 +00:00
'use strict';
var PEM = module.exports;
var Enc = require('./encoding.js');
PEM.packBlock = function (opts) {
2018-12-18 04:29:45 +00:00
// TODO allow for headers?
2018-12-18 04:08:46 +00:00
var n = opts.lineLength || 64;
var re = new RegExp('.{1,' + n + '}', 'g');
return '-----BEGIN ' + opts.type + '-----\n'
+ Enc.bufToBase64(opts.bytes).match(re).join('\n') + '\n'
+ '-----END ' + opts.type + '-----'
;
};