This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from adieuadieu/fix/typedefs
fix: en/decrypt function type definition issue
- Loading branch information
Showing
4 changed files
with
38 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 |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import kmsDecrypt from './decrypt' | ||
import kmsEncrypt, { InterfaceEncryptParameters } from './encrypt' | ||
|
||
export const encrypt = async ( | ||
parameters: | ||
| InterfaceEncryptParameters | ||
| ReadonlyArray<InterfaceEncryptParameters>, | ||
): Promise<string | ReadonlyArray<string>> => | ||
'plaintext' in parameters | ||
export async function encrypt( | ||
parameters: InterfaceEncryptParameters, | ||
): Promise<string> | ||
export async function encrypt( | ||
parameters: ReadonlyArray<InterfaceEncryptParameters>, | ||
): Promise<ReadonlyArray<string>> | ||
export async function encrypt(parameters: any): Promise<any> { | ||
return 'plaintext' in parameters | ||
? kmsEncrypt(parameters) | ||
: Promise.all(parameters.map(kmsEncrypt)) | ||
} | ||
|
||
export const decrypt = async ( | ||
ciphertext: undefined | string | ReadonlyArray<string>, | ||
): Promise<undefined | string | ReadonlyArray<string>> => | ||
typeof ciphertext === 'undefined' | ||
export async function decrypt(ciphertext: undefined): Promise<undefined> | ||
export async function decrypt(ciphertext: string): Promise<string> | ||
export async function decrypt( | ||
ciphertext: ReadonlyArray<string>, | ||
): Promise<ReadonlyArray<string>> | ||
export async function decrypt(ciphertext: any): Promise<any> { | ||
return typeof ciphertext === 'undefined' | ||
? undefined // useful in development when process.env.SECRET may be unset | ||
: typeof ciphertext === 'string' | ||
? kmsDecrypt(ciphertext) | ||
: Promise.all(ciphertext.map(kmsDecrypt)) | ||
} |
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