mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-09 03:30:09 +00:00
Fix readPkcs12 function types (#31612)
This commit is contained in:
11
types/pem/index.d.ts
vendored
11
types/pem/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/andris9/pem
|
||||
// Definitions by: Anthony Trinh <https://github.com/tony19>, Ruslan Arkhipau <https://github.com/DethAriel>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
/// <reference types="node" />
|
||||
|
||||
export interface ModuleConfiguration {
|
||||
/**
|
||||
@@ -135,6 +136,12 @@ export interface CertificateSubjectReadResult {
|
||||
emailAddress: string;
|
||||
}
|
||||
|
||||
export interface Pkcs12ReadResult {
|
||||
key: string;
|
||||
cert: string;
|
||||
ca: string[];
|
||||
}
|
||||
|
||||
export type Callback<T> = (error: any, result: T) => any;
|
||||
|
||||
/**
|
||||
@@ -244,8 +251,8 @@ export function createPkcs12(key: string, certificate: string, password: string,
|
||||
* @param callback Callback function with an error object and {pkcs12}
|
||||
* @returns the result of the callback
|
||||
*/
|
||||
export function readPkcs12(bufferOrPath: string, options: Pkcs12ReadOptions, callback: Callback<{ pkcs12: any }>): any;
|
||||
export function readPkcs12(bufferOrPath: string, callback: Callback<{ pkcs12: any }>): any;
|
||||
export function readPkcs12(bufferOrPath: Buffer | string, options: Pkcs12ReadOptions, callback: Callback<Pkcs12ReadResult>): any;
|
||||
export function readPkcs12(bufferOrPath: Buffer | string, callback: Callback<Pkcs12ReadResult>): any;
|
||||
|
||||
/**
|
||||
* Verifies the signing chain of the passed certificate
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as pem from 'pem';
|
||||
import * as fs from 'fs';
|
||||
|
||||
const tests = {
|
||||
'Create default sized dhparam key': (test: any) => {
|
||||
@@ -557,8 +558,21 @@ const tests = {
|
||||
test.ok(pkcs12.pkcs12);
|
||||
|
||||
// test.ok(fs.readdirSync('./tmp').length === 0);
|
||||
const pkcs12Buffer = new Buffer(pkcs12.pkcs12);
|
||||
|
||||
pem.readPkcs12(pkcs12.pkcs12, (error: any, keystore: any) => {
|
||||
pem.readPkcs12(pkcs12Buffer, (error: any, keystore: pem.Pkcs12ReadResult) => {
|
||||
test.ifError(error);
|
||||
test.ok(keystore);
|
||||
|
||||
test.equal(ca.certificate, keystore.ca[0]);
|
||||
test.equal(cert.certificate, keystore.cert);
|
||||
test.equal(cert.clientKey, keystore.key);
|
||||
});
|
||||
|
||||
const pkcs12File: string = __dirname + '/test.pkcs12';
|
||||
fs.writeFileSync(pkcs12File, pkcs12Buffer);
|
||||
|
||||
pem.readPkcs12(pkcs12File, (error: any, keystore: pem.Pkcs12ReadResult) => {
|
||||
test.ifError(error);
|
||||
test.ok(keystore);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user