(n: number)
| 68 | // ---- minimal DER encoding for the PKCS#1 -> PKCS#8 wrap ---- |
| 69 | |
| 70 | function derLength(n: number): number[] { |
| 71 | if (n < 0x80) return [n]; |
| 72 | const bytes: number[] = []; |
| 73 | let v = n; |
| 74 | while (v > 0) { |
| 75 | bytes.unshift(v & 0xff); |
| 76 | v >>= 8; |
| 77 | } |
| 78 | return [0x80 | bytes.length, ...bytes]; |
| 79 | } |
| 80 | |
| 81 | function derTLV(tag: number, content: Uint8Array): Uint8Array { |
| 82 | return Uint8Array.from([tag, ...derLength(content.length), ...content]); |