@@ -46,13 +46,16 @@ export enum PBEErrorCode {
4646
4747// Custom error class
4848export class PBEError extends Error {
49+ public readonly details : Record < string , unknown > | undefined
50+
4951 constructor (
5052 message : string ,
51- public code : PBEErrorCode ,
52- public details ?: Record < string , unknown >
53+ public readonly code : PBEErrorCode ,
54+ details ?: Record < string , unknown >
5355 ) {
5456 super ( message )
5557 this . name = 'PBEError'
58+ this . details = details
5659 }
5760}
5861
@@ -749,7 +752,7 @@ export function encryptPrivateKeyInfo(obj: any, password: string, options: Encry
749752 const saltBuffer = toNodeBuffer ( salt )
750753 const dk = pbkdf2 ( password , saltBuffer , count , dkLen , md , undefined )
751754 if ( ! dk ) throw new Error ( 'Failed to generate derived key' )
752-
755+ if ( ! cipherFn ) throw new Error ( 'Cipher function is not defined' )
753756 const iv = createBuffer ( getBytesSync ( ivLen ) )
754757 const cipher = cipherFn ( toByteStringBuffer ( dk ) )
755758 cipher . start ( { iv : createBuffer ( iv ) } )
@@ -1231,6 +1234,7 @@ export function getCipherForPBES2(oid: string, params: any, password: string): B
12311234 const saltBuffer = toNodeBuffer ( salt )
12321235 const dk = pbkdf2 ( password , saltBuffer , iterationCount , dkLen , md , undefined )
12331236 if ( ! dk ) throw new Error ( 'Failed to generate derived key' )
1237+ if ( ! cipherFn ) throw new Error ( 'Cipher function is not defined' )
12341238 const iv = capture . encIv
12351239 const cipher = cipherFn ( convertToString ( dk ) )
12361240 cipher . start ( { iv : createBuffer ( iv ) } )
0 commit comments