15 lines
376 B
JavaScript
15 lines
376 B
JavaScript
'use strict';
|
|
|
|
var PEM = module.exports;
|
|
var Enc = require('./encoding.js');
|
|
|
|
PEM.packBlock = function (opts) {
|
|
// TODO allow for headers?
|
|
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 + '-----'
|
|
;
|
|
};
|