Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
wh201906 committed Jul 23, 2024
1 parent d3bd657 commit e4eb58c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/app-mobile/services/e2ee/crypto.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions packages/lib/services/e2ee/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Crypto, HashAlgorithm } from './types';
import { Crypto, Digest } from './types';
import { promisify } from 'util';
import {
getCiphers as nodeGetCiphers, getHashes as nodeGetHashes,
randomBytes as nodeRandomBytes,
pbkdf2 as nodePbkdf2,
} from 'crypto';

type NodeDigestNameMap = Record<HashAlgorithm, string>;
type DigestNameMap = Record<Digest, string>;

const crypto: Crypto = {

Expand All @@ -23,16 +23,16 @@ 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',
'SHA-384': 'sha384',
'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);
Expand Down
6 changes: 3 additions & 3 deletions packages/lib/services/e2ee/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export interface Crypto {
getCiphers(): string[];
getHashes(): string[];
randomBytes(size: number): Promise<CryptoBuffer>;
pbkdf2Raw(password: string, salt: CryptoBuffer, iterations: number, keylen: number, digest: HashAlgorithm): Promise<CryptoBuffer>;
pbkdf2Raw(password: string, salt: CryptoBuffer, iterations: number, keylen: number, digest: Digest): Promise<CryptoBuffer>;
}

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'
Expand Down

0 comments on commit e4eb58c

Please sign in to comment.