From e4eb58c21df17d51000610cae52594835c9eafd6 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Tue, 23 Jul 2024 21:50:24 +0800 Subject: [PATCH] Rename --- packages/app-mobile/services/e2ee/crypto.ts | 4 ++-- packages/lib/services/e2ee/crypto.ts | 10 +++++----- packages/lib/services/e2ee/types.ts | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/app-mobile/services/e2ee/crypto.ts b/packages/app-mobile/services/e2ee/crypto.ts index 903d25848d8..ca01303b9e5 100644 --- a/packages/app-mobile/services/e2ee/crypto.ts +++ b/packages/app-mobile/services/e2ee/crypto.ts @@ -1,4 +1,4 @@ -import { Crypto, CryptoBuffer, HashAlgorithm } from '@joplin/lib/services/e2ee/types'; +import { Crypto, CryptoBuffer, Digest } from '@joplin/lib/services/e2ee/types'; import QuickCrypto from 'react-native-quick-crypto'; const crypto: Crypto = { @@ -23,7 +23,7 @@ const crypto: Crypto = { }); }, - pbkdf2Raw: async (password: string, salt: CryptoBuffer, iterations: number, keylen: number, digest: HashAlgorithm) => { + pbkdf2Raw: async (password: string, salt: CryptoBuffer, iterations: number, keylen: number, digest: Digest) => { return new Promise((resolve, reject) => { QuickCrypto.pbkdf2(password, salt, iterations, keylen, digest, (error, result) => { if (error) { diff --git a/packages/lib/services/e2ee/crypto.ts b/packages/lib/services/e2ee/crypto.ts index 66c31b98fce..c0a5495af9f 100644 --- a/packages/lib/services/e2ee/crypto.ts +++ b/packages/lib/services/e2ee/crypto.ts @@ -1,4 +1,4 @@ -import { Crypto, HashAlgorithm } from './types'; +import { Crypto, Digest } from './types'; import { promisify } from 'util'; import { getCiphers as nodeGetCiphers, getHashes as nodeGetHashes, @@ -6,7 +6,7 @@ import { pbkdf2 as nodePbkdf2, } from 'crypto'; -type NodeDigestNameMap = Record; +type DigestNameMap = Record; const crypto: Crypto = { @@ -23,8 +23,8 @@ const crypto: Crypto = { return randomBytesAsync(size); }, - pbkdf2Raw: async (password: string, salt: Buffer, iterations: number, keylen: number, digest: HashAlgorithm) => { - const nodeDigestNameMap: NodeDigestNameMap = { + pbkdf2Raw: async (password: string, salt: Buffer, iterations: number, keylen: number, digest: Digest) => { + const digestNameMap: DigestNameMap = { 'SHA-1': 'sha1', 'SHA-224': 'sha224', 'SHA-256': 'sha256', @@ -32,7 +32,7 @@ const crypto: Crypto = { 'SHA-512': 'sha512', 'RIPEMD-160': 'ripemd160', }; - const nodeDigestName = nodeDigestNameMap[digest]; + const nodeDigestName = digestNameMap[digest]; const pbkdf2Async = promisify(nodePbkdf2); return pbkdf2Async(password, salt, iterations, keylen, nodeDigestName); diff --git a/packages/lib/services/e2ee/types.ts b/packages/lib/services/e2ee/types.ts index 085b8a47019..1c8ce18766e 100644 --- a/packages/lib/services/e2ee/types.ts +++ b/packages/lib/services/e2ee/types.ts @@ -30,15 +30,15 @@ export interface Crypto { getCiphers(): string[]; getHashes(): string[]; randomBytes(size: number): Promise; - pbkdf2Raw(password: string, salt: CryptoBuffer, iterations: number, keylen: number, digest: HashAlgorithm): Promise; + pbkdf2Raw(password: string, salt: CryptoBuffer, iterations: number, keylen: number, digest: Digest): Promise; } export interface CryptoBuffer extends Uint8Array { toString(encoding?: BufferEncoding, start?: number, end?: number): string; } -// From react-native-quick-crypto -export type HashAlgorithm = +// From react-native-quick-crypto.HashAlgorithm +export type Digest = | 'SHA-1' | 'SHA-224' | 'SHA-256'