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

14 lines
347 B
JavaScript

'use strict';
var PEM = module.exports;
var Enc = require('./encoding.js');
PEM.packBlock = function (opts) {
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 + '-----'
;
};