Skip to content

Commit

Permalink
Remove class
Browse files Browse the repository at this point in the history
  • Loading branch information
wh201906 committed Jul 8, 2024
1 parent 71f0204 commit 17aa0fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
22 changes: 11 additions & 11 deletions packages/app-mobile/services/e2ee/NativeEncryption.react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { NativeEncryptionInterface } from '@joplin/lib/services/e2ee/types';
import crypto from 'react-native-quick-crypto';
import { HashAlgorithm } from 'react-native-quick-crypto/lib/typescript/keys';

class NativeEncryption implements NativeEncryptionInterface {
public getCiphers(): string[] {
const NativeEncryption: NativeEncryptionInterface = {

getCiphers: (): string[] => {
return crypto.getCiphers();
}
},

public getHashes(): string[] {
getHashes: (): string[] => {
return crypto.getHashes();
}
},

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: remove the type "any" here
public async randomBytes(size: number): Promise<Buffer | any> {
randomBytes: async (size: number): Promise<Buffer | any> => {
return new Promise((resolve, reject) => {
crypto.randomBytes(size, (error, result) => {
if (error) {
Expand All @@ -22,10 +23,10 @@ class NativeEncryption implements NativeEncryptionInterface {
}
});
});
}
},

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: remove the type "any" here
public async pbkdf2Raw(password: string, salt: Buffer, iterations: number, keylen: number, digest: string): Promise<Buffer | any> {
pbkdf2Raw: async (password: string, salt: Buffer, iterations: number, keylen: number, digest: string): Promise<Buffer | any> => {
const digestMap: { [key: string]: HashAlgorithm } = {
'sha1': 'SHA-1',
'sha224': 'SHA-224',
Expand All @@ -44,8 +45,7 @@ class NativeEncryption implements NativeEncryptionInterface {
}
});
});
}

}
},
};

export default NativeEncryption;
4 changes: 1 addition & 3 deletions packages/app-mobile/utils/shim-init-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ function shimInit() {
shim.Geolocation = GeolocationReact;
shim.sjclModule = require('@joplin/lib/vendor/sjcl-rn.js');

// copied from generated shim-init-node.js. Strange but works
const NativeEncryption = require('../services/e2ee/NativeEncryption.react-native');
shim.NativeEncryption = new NativeEncryption.default;
shim.NativeEncryption = require('../services/e2ee/NativeEncryption.react-native').default;

shim.fsDriver = () => {
if (!shim.fsDriver_) {
Expand Down
21 changes: 11 additions & 10 deletions packages/lib/services/e2ee/NativeEncryption.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ import { NativeEncryptionInterface } from './types';
import { promisify } from 'util';
import crypto = require('crypto');

class NativeEncryption implements NativeEncryptionInterface {
public getCiphers(): string[] {
const NativeEncryption: NativeEncryptionInterface = {

getCiphers: (): string[] => {
return crypto.getCiphers();
}
},

public getHashes(): string[] {
getHashes: (): string[] => {
return crypto.getHashes();
}
},

public async randomBytes(size: number): Promise<Buffer> {
randomBytes: async (size: number): Promise<Buffer> => {
const randomBytesAsync = promisify(crypto.randomBytes);
return randomBytesAsync(size);
}
},

public async pbkdf2Raw(password: string, salt: Buffer, iterations: number, keylen: number, digest: string): Promise<Buffer> {
pbkdf2Raw: async (password: string, salt: Buffer, iterations: number, keylen: number, digest: string): Promise<Buffer> => {
const digestMap: { [key: string]: string } = {
'sha-1': 'sha1',
'sha-224': 'sha224',
Expand All @@ -29,7 +30,7 @@ class NativeEncryption implements NativeEncryptionInterface {

const pbkdf2Async = promisify(crypto.pbkdf2);
return pbkdf2Async(password, salt, iterations, keylen, digestAlgorithm);
}
}
},
};

export default NativeEncryption;
2 changes: 1 addition & 1 deletion packages/lib/shim-init-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function shimInit(options: ShimInitOptions = null) {
shim.Geolocation = GeolocationNode;
shim.FormData = require('form-data');
shim.sjclModule = require('./vendor/sjcl.js');
shim.NativeEncryption = new NativeEncryption;
shim.NativeEncryption = NativeEncryption;
shim.electronBridge_ = options.electronBridge;

shim.fsDriver = () => {
Expand Down

0 comments on commit 17aa0fd

Please sign in to comment.