pem.d.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /// <reference types="node" />
  2. import { inspect } from 'util';
  3. /**
  4. * Implements the PEM data encoding, which originated in Privacy
  5. * Enhanced Mail. The most common use of PEM encoding today is in TLS keys and
  6. * certificates. See RFC 1421.
  7. *
  8. * A PEM represents a PEM encoded structure.
  9. *
  10. * The encoded form is:
  11. * ```
  12. * -----BEGIN Type-----
  13. * Headers
  14. * base64-encoded Bytes
  15. * -----END Type-----
  16. * ```
  17. *
  18. * Headers like:
  19. * ```
  20. * Proc-Type: 4,ENCRYPTED
  21. * DEK-Info: DES-EDE3-CBC,29DE8F99F382D122
  22. * ```
  23. */
  24. export declare class PEM {
  25. /**
  26. * Parse PEM formatted buffer, returns one or more PEM object.
  27. * If there is no PEM object, it will throw error.
  28. * @param data buffer to parse.
  29. */
  30. static parse(data: Buffer): PEM[];
  31. /**
  32. * The type, taken from the preamble (i.e. "RSA PRIVATE KEY").
  33. */
  34. type: string;
  35. /**
  36. * The decoded bytes of the contents. Typically a DER encoded ASN.1 structure.
  37. */
  38. body: Buffer;
  39. private headers;
  40. constructor(type: string, body: Buffer);
  41. /**
  42. * Return exists Proc-Type header or empty string
  43. */
  44. readonly procType: string;
  45. /**
  46. * Return a header or empty string with given key.
  47. */
  48. getHeader(key: string): string;
  49. /**
  50. * Set a header with given key/value.
  51. */
  52. setHeader(key: string, val: string): void;
  53. /**
  54. * Encode to PEM formatted string.
  55. */
  56. toString(): string;
  57. /**
  58. * Encode to PEM formatted buffer.
  59. */
  60. toBuffer(): Buffer;
  61. /**
  62. * Returns the body.
  63. */
  64. valueOf(): Buffer;
  65. /**
  66. * Return a friendly JSON object for debuging.
  67. */
  68. toJSON(): any;
  69. protected [inspect.custom](_depth: any, options: any): string;
  70. }