|
| 1 | +"use strict"; |
| 2 | +/** |
| 3 | + * ICryptoModule adapter that delegates to the legacy Crypto implementation. |
| 4 | + * |
| 5 | + * This bridges the RN path to the endpoints that expect an ICryptoModule when |
| 6 | + * only a cipherKey is provided. |
| 7 | + */ |
| 8 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 9 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 10 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 11 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 12 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 13 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 14 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 15 | + }); |
| 16 | +}; |
| 17 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 18 | +const buffer_1 = require("buffer"); |
| 19 | +class LegacyCryptoModuleAdapter { |
| 20 | + constructor(legacy) { |
| 21 | + this.legacy = legacy; |
| 22 | + } |
| 23 | + // Allow SDK to update logger on the underlying legacy crypto. |
| 24 | + set logger(logger) { |
| 25 | + // legacy logger setter accepts LoggerManager | undefined |
| 26 | + this.legacy.logger = logger; |
| 27 | + } |
| 28 | + // -------------------------------------------------------- |
| 29 | + // --------------------- Encryption ----------------------- |
| 30 | + // -------------------------------------------------------- |
| 31 | + encrypt(data) { |
| 32 | + const plaintext = typeof data === 'string' ? data : buffer_1.Buffer.from(new Uint8Array(data)).toString('utf8'); |
| 33 | + // Legacy crypto returns a base64 string. |
| 34 | + return this.legacy.encrypt(plaintext); |
| 35 | + } |
| 36 | + encryptFile(_file, _File) { |
| 37 | + return __awaiter(this, void 0, void 0, function* () { |
| 38 | + // Not used on RN when cipherKey is set: file endpoints take the cipherKey + cryptography path. |
| 39 | + return undefined; |
| 40 | + }); |
| 41 | + } |
| 42 | + // -------------------------------------------------------- |
| 43 | + // --------------------- Decryption ----------------------- |
| 44 | + // -------------------------------------------------------- |
| 45 | + decrypt(data) { |
| 46 | + let ciphertextB64; |
| 47 | + if (typeof data === 'string') |
| 48 | + ciphertextB64 = data; |
| 49 | + else |
| 50 | + ciphertextB64 = buffer_1.Buffer.from(new Uint8Array(data)).toString('base64'); |
| 51 | + const decrypted = this.legacy.decrypt(ciphertextB64); |
| 52 | + // Legacy decrypt returns object or string; ICryptoModule allows returning ArrayBuffer | Payload | null. |
| 53 | + return decrypted; |
| 54 | + } |
| 55 | + decryptFile(_file, _File) { |
| 56 | + return __awaiter(this, void 0, void 0, function* () { |
| 57 | + // Not used on RN when cipherKey is set: file endpoints take the cipherKey + cryptography path. |
| 58 | + return undefined; |
| 59 | + }); |
| 60 | + } |
| 61 | +} |
| 62 | +exports.default = LegacyCryptoModuleAdapter; |
0 commit comments