/// <summary> /// Adds a file to the zip stream /// </summary> /// <param name="dictItemTypes"></param> /// <param name="zipOutputStream"></param> /// <param name="currentItemType"></param> /// <param name="currentExportFormat"></param> private static void AddFileToArchive(Dictionary <BitwardenObject.ItemType, List <ExportItem> > dictItemTypes, ZipOutputStream zipOutputStream, BitwardenObject.ItemType currentItemType, ZipAes256ExportFormat currentExportFormat) { _log.Info($"Archiving [{currentExportFormat}/{currentItemType}]"); IZipAes256Exporter exporter = ZipAes256ExportSelector.GetExporter(currentExportFormat); //Not all Export Formats do support all item-types (ex. 1Password has no Identity format specified) // -> No files for that will be exported. if (exporter.GetSupportedItemTypes().Contains(currentItemType)) { byte[] buffer = exporter.GetFileContent(dictItemTypes[currentItemType], currentItemType); if (buffer != null) { using (MemoryStream currentFormatFileStream = new MemoryStream(buffer)) { ZipEntry entry = new ZipEntry($"{currentExportFormat}\\{currentExportFormat}-{currentItemType}.{exporter.GetFileExtension()}"); entry.AESKeySize = 256; entry.Size = buffer.Length; zipOutputStream.PutNextEntry(entry); StreamUtils.Copy(currentFormatFileStream, zipOutputStream, new byte[4096]); zipOutputStream.CloseEntry(); currentFormatFileStream.Close(); } } else { _log.Error($"No output could be created for {currentExportFormat}:{currentItemType}!"); } } else { _log.Warn($"[{currentExportFormat} does not support [{currentItemType}]! No file will be archived, the information will be available from the json export only!"); } }
public UnsupportedItemTypeException(IZipAes256Exporter exporter, BitwardenObject.ItemType itemType) { Exporter = exporter; ItemType = itemType; }