-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@sounisi5011/encrypted-archive): validate password type (#557)
* fix(@sounisi5011/encrypted-archive): validate password type Fixed a bug found while adding tests within [#554]. [#554]: #554 * refactor(@sounisi5011/encrypted-archive): reduce similar blocks Code Climate reported: + Similar blocks of code found in 2 locations. Consider refactoring.
- Loading branch information
1 parent
78e3fea
commit e3f4a0c
Showing
5 changed files
with
30 additions
and
16 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
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
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,25 @@ | ||
import { InputDataType, isInputDataType } from './types'; | ||
import { printObject } from './utils'; | ||
|
||
function createInputDataTypeErrorMessage(prefix: string, actual: unknown): string { | ||
return ( | ||
prefix | ||
+ ` must be of type string or an instance of Buffer, TypedArray, DataView, or ArrayBuffer.` | ||
+ ` Received ${printObject(actual)}` | ||
); | ||
} | ||
|
||
export function validateChunk(chunk: unknown): InputDataType { | ||
if (!isInputDataType(chunk)) { | ||
throw new TypeError(createInputDataTypeErrorMessage('Invalid type chunk received. Each chunk', chunk)); | ||
} | ||
return chunk; | ||
} | ||
|
||
export function validatePassword(password: unknown): asserts password is InputDataType { | ||
if (!isInputDataType(password)) { | ||
throw new TypeError( | ||
createInputDataTypeErrorMessage('Invalid type password received. The password argument', password), | ||
); | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.