import type { TransportAuthentication } from './security.ts' export function buildTlsConnectOptions(auth: TransportAuthentication) { const toBuf = (v: Uint8Array | string) => (typeof v === 'string' ? v : Buffer.from(v)) const toBufOrArray = (v: TransportAuthentication['ca']) => Array.isArray(v) ? v.map(toBuf) : v !== undefined ? toBuf(v) : undefined return { pfx: auth.pfx ? [{ buf: Buffer.from(auth.pfx), passphrase: auth.passphrase }] : undefined, cert: auth.cert !== undefined ? toBuf(auth.cert) : undefined, key: auth.key !== undefined ? toBuf(auth.key) : undefined, ca: toBufOrArray(auth.ca), passphrase: auth.passphrase, rejectUnauthorized: auth.rejectUnauthorized ?? true, } }