一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
34 行
1.0 KiB
TypeScript
34 行
1.0 KiB
TypeScript
import type { webcrypto } from 'node:crypto';
|
|
import { PublicKeyAlgorithm } from '../../types';
|
|
import StringToBufferWrapper from './StringToBufferWrapper';
|
|
import WebCryptoRsa, { WebCryptoSlice } from './WebCryptoRsa';
|
|
import LongDataWrapper from './LongDataWrapper';
|
|
|
|
const buildRsaCryptoProvider = (rsaMode: PublicKeyAlgorithm, crypto: WebCryptoSlice|typeof webcrypto) => {
|
|
// Cast: Old versions of @types/node don't include crypto.subtle:
|
|
const cryptoSlice = crypto as unknown as WebCryptoSlice;
|
|
if (rsaMode === PublicKeyAlgorithm.RsaV2) {
|
|
const keySizeBits = 2048;
|
|
return new StringToBufferWrapper(
|
|
new LongDataWrapper(
|
|
new WebCryptoRsa(
|
|
cryptoSlice,
|
|
{ modulusLengthBits: keySizeBits },
|
|
),
|
|
keySizeBits / 8,
|
|
),
|
|
);
|
|
} else if (rsaMode === PublicKeyAlgorithm.RsaV3) {
|
|
return new StringToBufferWrapper(
|
|
new WebCryptoRsa(
|
|
cryptoSlice,
|
|
{ modulusLengthBits: 4096 },
|
|
),
|
|
);
|
|
} else {
|
|
throw new Error(`Unsupported mode for webCrypto: ${rsaMode}`);
|
|
}
|
|
};
|
|
|
|
export default buildRsaCryptoProvider;
|