Skip to content

Core decryptFile + encryptFile methods #341

Description

@tomholub

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());
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions