2023-11-04 06:44:18 +03:00
|
|
|
import { BaseNodeCryptoProvider } from '@mtcute/core/src/utils/crypto/node.js'
|
2023-10-16 19:23:53 +03:00
|
|
|
import { IEncryptionScheme } from '@mtcute/core/utils.js'
|
|
|
|
|
|
|
|
import { native } from './native.cjs'
|
2022-06-30 16:32:56 +03:00
|
|
|
|
2023-06-05 03:30:48 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2023-10-16 19:23:53 +03:00
|
|
|
const { ige256_decrypt, ige256_encrypt } = native
|
2021-05-01 21:22:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Crypto provider for NodeJS that uses a native extension to improve
|
|
|
|
* performance of the IGE mode.
|
|
|
|
*
|
|
|
|
* Other modes are supported natively by OpenSSL, and
|
|
|
|
* they *are* faster than the custom ones.
|
|
|
|
*/
|
2023-11-04 06:44:18 +03:00
|
|
|
export class NodeNativeCryptoProvider extends BaseNodeCryptoProvider {
|
2023-10-16 19:23:53 +03:00
|
|
|
createAesIge(key: Uint8Array, iv: Uint8Array): IEncryptionScheme {
|
2021-05-01 21:22:20 +03:00
|
|
|
return {
|
2023-10-16 19:23:53 +03:00
|
|
|
encrypt(data: Uint8Array): Uint8Array {
|
2021-05-01 21:22:20 +03:00
|
|
|
return ige256_encrypt(data, key, iv)
|
|
|
|
},
|
2023-10-16 19:23:53 +03:00
|
|
|
decrypt(data: Uint8Array): Uint8Array {
|
2021-05-01 21:22:20 +03:00
|
|
|
return ige256_decrypt(data, key, iv)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|