-
Notifications
You must be signed in to change notification settings - Fork 11
Closed
Description
part of #275, do before #195 or #196
need to add the following method to Core. Roughly:
public func decryptFile(encrypted: Data, keys: [PrvKeyInfo], msgPwd: String?) throws -> CoreRes.DecryptFile {
let json: [String : Any?]? = ["keys": try keys.map { try $0.toDict() }, "msgPwd": msgPwd]
let decrypted = try call("decryptFile", jsonDict: json, data: encrypted)
let meta = try decrypted.json.decodeJson(as: CoreRes.DecryptFileMeta.self)
return CoreRes.DecryptFile(...)
}here is the code of the typescript handler:
public decryptFile = async (uncheckedReq: any, data: Buffers): Promise<Buffers> => {
const { keys: kisWithPp, msgPwd } = ValidateInput.decryptFile(uncheckedReq);
const decryptedMeta = await PgpMsg.decrypt({ kisWithPp, encryptedData: Buf.concat(data), msgPwd });
if (!decryptedMeta.success) {
decryptedMeta.message = undefined;
return fmtRes(decryptedMeta);
}
return fmtRes({ success: true, name: decryptedMeta.filename || '' }, decryptedMeta.content);
}need to be mindful of ability to handle the error scenario.
similarly for encryptFile:
public encryptFile = async (uncheckedReq: any, data: Buffers): Promise<Buffers> => {
const req = ValidateInput.encryptFile(uncheckedReq);
const encrypted = await PgpMsg.encrypt({ pubkeys: req.pubKeys, data: Buf.concat(data), filename: req.name, armor: false }) as OpenPGP.EncryptBinaryResult;
return fmtRes({}, encrypted.message.packets.write());
}
Reactions are currently unavailable