-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typings: Add incomplete types for mac-ca & win-ca
Needed for interoperability with TypeScript. Note that these are rather incomplete; they're enough for our uses, but in particular for win-ca the API exposes a rather complicated surface for retrofitting types. Signed-off-by: Mark Yen <[email protected]>
- Loading branch information
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
declare module 'mac-ca/lib/fomatter' { | ||
// eslint-disable-next-line import/no-duplicates | ||
import * as forge from 'node-forge'; | ||
|
||
export enum validFormats { | ||
der = 0, | ||
pem = 1, | ||
txt = 2, | ||
asn1 = 3, | ||
} | ||
|
||
export interface Asn1 { | ||
serial: forge.asn1.Asn1; | ||
issuer: forge.asn1.Asn1; | ||
valid: forge.asn1.Asn1; | ||
subject: forge.asn1.Asn1; | ||
} | ||
|
||
/* eslint-disable no-redeclare */ | ||
export function transform(format: validFormats.der): forge.util.ByteStringBuffer; | ||
export function transform(format: validFormats.pem): string; | ||
export function transform(format: validFormats.txt): string; | ||
export function transform(format: validFormats.asn1): Asn1; | ||
export function transform(format: undefined): forge.pki.Certificate; | ||
/* eslint-enable no-redeclare */ | ||
} | ||
|
||
declare module 'mac-ca' { | ||
// eslint-disable-next-line import/no-duplicates | ||
import * as forge from 'node-forge'; | ||
import { transform, validFormats, Asn1 } from 'mac-ca/lib/fomatter'; | ||
|
||
export { validFormats as der2 }; | ||
|
||
type transformResult = ReturnType<typeof transform>; | ||
|
||
/* eslint-disable no-redeclare */ | ||
export function all(format: validFormats.der): forge.util.ByteStringBuffer[]; | ||
export function all(format: validFormats.pem): string[]; | ||
export function all(format: validFormats.txt): string[]; | ||
export function all(format: validFormats.asn1): Asn1[]; | ||
export function all(format?: undefined): forge.pki.Certificate[]; | ||
/* eslint-enable no-redeclare */ | ||
|
||
type eachCallback = (item: transformResult) => void; | ||
|
||
/* eslint-disable no-redeclare */ | ||
export function each(callback: (certificate: forge.pki.Certificate) => void): void; | ||
export function each(format: validFormats.der, callback: (der: forge.util.ByteStringBuffer) => void): void; | ||
export function each(format: validFormats.pem, callback: (pem: string) => void): void; | ||
export function each(format: validFormats.txt, callback: (text: string) => void): void; | ||
export function each(format: validFormats.asn1, callback: (asn1: Asn1) => void): void; | ||
export function each(format: undefined, callback: (certificate: forge.pki.Certificate) => void): void; | ||
export function each(callback: (certificate: forge.pki.Certificate) => void): void; | ||
/* eslint-enable no-redeclare */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
declare module 'win-ca/der2' { | ||
import * as forge from 'node-forge'; | ||
|
||
namespace der2 { | ||
export enum format { | ||
der = 0, | ||
pem = 1, | ||
txt = 2, | ||
asn1 = 3, | ||
x509 = 4, | ||
forge = x509, | ||
} | ||
const der: typeof format.der; | ||
const pem: typeof format.pem; | ||
const txt: typeof format.txt; | ||
const asn1: typeof format.asn1; | ||
const x509: typeof format.x509; | ||
const forge: typeof format.forge; | ||
} | ||
|
||
/** Types that Buffer.from() can take as an argument. */ | ||
type bufferFromType = number[] | ArrayBuffer | SharedArrayBuffer | Buffer | ||
|
||
function der(it: Buffer | bufferFromType): Buffer; | ||
|
||
function pem(it: Buffer | bufferFromType): string | ||
|
||
function txt(it: Buffer): string | ||
|
||
interface Asn1 { | ||
serial: forge.asn1.Asn1; | ||
issuer: forge.asn1.Asn1; | ||
valid: forge.asn1.Asn1; | ||
subject: forge.asn1.Asn1; | ||
} | ||
|
||
function asn1(it: Buffer): Asn1; | ||
|
||
function x509(it: Buffer): forge.pki.Certificate; | ||
|
||
function der2(): typeof der; | ||
function der2(format: der2.format.der): typeof der; | ||
function der2(format: der2.format.der, blob: Buffer | bufferFromType): Buffer; | ||
function der2(format: der2.format.pem): typeof pem; | ||
function der2(format: der2.format.pem, blob: Buffer | bufferFromType): string; | ||
function der2(format: der2.format.txt): typeof txt; | ||
function der2(format: der2.format.txt, blob: Buffer): string; | ||
function der2(format: der2.format.asn1): typeof asn1; | ||
function der2(format: der2.format.asn1, blob: Buffer): Asn1; | ||
function der2(format: der2.format.x509): typeof x509; | ||
function der2(format: der2.format.x509, blob: Buffer): forge.pki.Certificate; | ||
|
||
export default der2; | ||
|
||
} | ||
|
||
declare module 'win-ca/lib/save' { | ||
|
||
} | ||
|
||
declare module 'win-ca' { | ||
import _der2 from 'win-ca/der2'; | ||
|
||
interface apiOptions { | ||
disabled?: boolean; | ||
fallback?: boolean; | ||
store?: string[]; | ||
async?: boolean; | ||
unique?: boolean; | ||
format?: _der2.format; | ||
ondata?: any[] | ((cert: any) => void); | ||
onend?: () => void; | ||
generator?: boolean; | ||
inject?: boolean | '+'; | ||
save?: boolean | string | string[]; | ||
onsave?: (path: string | undefined) => void; | ||
} | ||
namespace api { | ||
namespace der2 { | ||
const der = _der2.der; | ||
const pem = _der2.pem; | ||
const txt = _der2.txt; | ||
const asn1 = _der2.asn1; | ||
const x509 = _der2.x509; | ||
const forge = _der2.forge; | ||
} | ||
} | ||
function api(params?: apiOptions): void; | ||
export default api; | ||
} |