Skip to content

Commit ec7b7e1

Browse files
committed
refactor: add phc saltEncoding option
1 parent 9ee2ce2 commit ec7b7e1

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

lib/phc.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function toPhc ( { id, version, params, salt, hash, defaultParams, sortPa
101101
return string;
102102
}
103103

104-
export function fromPhc ( string, { defaultParams, decodeNumbers = true, decodeSalt = true, decodeHash = true } = {} ) {
104+
export function fromPhc ( string, { defaultParams, decodeNumbers = true, saltEncoding = "base64" } = {} ) {
105105
const match = string.match( PHC_RE );
106106
if ( !match ) throw "PHC string is not valid";
107107

@@ -110,14 +110,10 @@ export function fromPhc ( string, { defaultParams, decodeNumbers = true, decodeS
110110
"version": undefined,
111111
"params": undefined,
112112
"salt": match.groups.salt
113-
? ( decodeSalt
114-
? Buffer.from( match.groups.salt, "base64" )
115-
: match.groups.salt )
113+
? Buffer.from( match.groups.salt, saltEncoding )
116114
: undefined,
117115
"hash": match.groups.hash
118-
? ( decodeHash
119-
? Buffer.from( match.groups.hash, "base64" )
120-
: match.groups.hash )
116+
? Buffer.from( match.groups.hash, "base64" )
121117
: undefined,
122118
};
123119

0 commit comments

Comments
 (0)