mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-10 03:27:05 +00:00
feat(torrents): add encryption policy
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
canonicalizeDownloadFileName,
|
||||
isValidTorrentExcludeTrackerList,
|
||||
isValidTorrentTrackerList,
|
||||
normalizeTorrentEncryptionPolicy,
|
||||
normalizeTorrentPrioritizePiece,
|
||||
redactDownloadForPersistence,
|
||||
resolveDownloadConnections
|
||||
@@ -92,6 +93,20 @@ describe('Torrent piece priority validation', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Torrent encryption policy validation', () => {
|
||||
it('accepts only the canonical policy states', () => {
|
||||
expect(normalizeTorrentEncryptionPolicy('disabled')).toBe('disabled');
|
||||
expect(normalizeTorrentEncryptionPolicy('require-crypto')).toBe('require-crypto');
|
||||
expect(normalizeTorrentEncryptionPolicy('force-encryption')).toBe('force-encryption');
|
||||
});
|
||||
|
||||
it('clears unknown or malformed persisted values', () => {
|
||||
expect(normalizeTorrentEncryptionPolicy(undefined)).toBeUndefined();
|
||||
expect(normalizeTorrentEncryptionPolicy('arc4')).toBeUndefined();
|
||||
expect(normalizeTorrentEncryptionPolicy(true)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('download connection resolution', () => {
|
||||
it('uses a clamped fallback for legacy rows without a saved value', () => {
|
||||
expect(resolveDownloadConnections(undefined, 8)).toBe(8);
|
||||
|
||||
@@ -44,6 +44,27 @@ export const isTransferActiveStatus = (status: DownloadStatus): boolean =>
|
||||
export const DOWNLOAD_CONNECTIONS_MIN = 1;
|
||||
export const DOWNLOAD_CONNECTIONS_MAX = 16;
|
||||
|
||||
export const TORRENT_ENCRYPTION_POLICY_DISABLED = 'disabled' as const;
|
||||
export const TORRENT_ENCRYPTION_POLICY_REQUIRE_CRYPTO = 'require-crypto' as const;
|
||||
export const TORRENT_ENCRYPTION_POLICY_FORCE_ENCRYPTION = 'force-encryption' as const;
|
||||
export type TorrentEncryptionPolicy =
|
||||
| typeof TORRENT_ENCRYPTION_POLICY_DISABLED
|
||||
| typeof TORRENT_ENCRYPTION_POLICY_REQUIRE_CRYPTO
|
||||
| typeof TORRENT_ENCRYPTION_POLICY_FORCE_ENCRYPTION;
|
||||
|
||||
export const normalizeTorrentEncryptionPolicy = (
|
||||
value: unknown
|
||||
): TorrentEncryptionPolicy | undefined => {
|
||||
if (
|
||||
value === TORRENT_ENCRYPTION_POLICY_DISABLED ||
|
||||
value === TORRENT_ENCRYPTION_POLICY_REQUIRE_CRYPTO ||
|
||||
value === TORRENT_ENCRYPTION_POLICY_FORCE_ENCRYPTION
|
||||
) {
|
||||
return value;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
// Keep every filename component within the common cross-platform filesystem
|
||||
// limit. Count UTF-8 bytes because POSIX filesystems enforce bytes, while this
|
||||
// bound is also conservative for Windows filename components.
|
||||
|
||||
Reference in New Issue
Block a user