blob: d2487e1cedb273eb16b836288286acad8d03cbc5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// Copyright 2017 Fedor Indutny. All rights reserved. MIT license.
import { DEREncoder } from "internal:deno_node/polyfills/_crypto/crypto_browserify/asn1.js/encoders/der.js";
export function PEMEncoder(entity) {
DEREncoder.call(this, entity);
this.enc = "pem";
}
// inherits(PEMEncoder, DEREncoder);
PEMEncoder.prototype = Object.create(DEREncoder.prototype, {
constructor: {
value: PEMEncoder,
enumerable: false,
writable: true,
configurable: true,
},
});
PEMEncoder.prototype.encode = function encode(data, options) {
const buf = DEREncoder.prototype.encode.call(this, data);
const p = buf.toString("base64");
const out = ["-----BEGIN " + options.label + "-----"];
for (let i = 0; i < p.length; i += 64) {
out.push(p.slice(i, i + 64));
}
out.push("-----END " + options.label + "-----");
return out.join("\n");
};
|