diff --git a/CDP4Common/CDP4Common.csproj b/CDP4Common/CDP4Common.csproj index 6c901a3f..ac05277d 100644 --- a/CDP4Common/CDP4Common.csproj +++ b/CDP4Common/CDP4Common.csproj @@ -20,11 +20,17 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [ADD] SharpZipLibUtils + [ADD] SharpZipLibExtension Methods README.md + + + + + + diff --git a/CDP4Common/Extensions/StreamExtensions.cs b/CDP4Common/Extensions/StreamExtensions.cs new file mode 100644 index 00000000..5d45e730 --- /dev/null +++ b/CDP4Common/Extensions/StreamExtensions.cs @@ -0,0 +1,51 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4Common.Extensions +{ + using System.IO; + + using ICSharpCode.SharpZipLib.Zip; + + /// + /// A class containing extension methods for objects + /// + public static class StreamExtensions + { + /// + /// Create a to create an encrypted zip file + /// + /// The input to write to + /// The password to be used to protect the data + /// The created + public static ZipOutputStream CreateEncryptableZipOutputStream(this Stream inputStream, string password) + { + var zipStream = new ZipOutputStream(inputStream); + zipStream.Password = password; + zipStream.IsStreamOwner = true; // underlying streams will be forcibly closed + + return zipStream; + } + } +} diff --git a/CDP4Common/Encryption/SharpZipLibUtils.cs b/CDP4Common/Extensions/ZipOutputStreamExtensions.cs similarity index 70% rename from CDP4Common/Encryption/SharpZipLibUtils.cs rename to CDP4Common/Extensions/ZipOutputStreamExtensions.cs index dec047f7..a56d118a 100644 --- a/CDP4Common/Encryption/SharpZipLibUtils.cs +++ b/CDP4Common/Extensions/ZipOutputStreamExtensions.cs @@ -1,5 +1,5 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// +// // Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -22,31 +22,21 @@ // // ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4Common.Encryption +namespace CDP4Common.Extensions { using System.IO; - + using ICSharpCode.SharpZipLib.Zip; /// - /// A class containing Helper Methods for working with SharpZipLib and creating AES 256 encrypted zip files + /// A class containing Extension Methods for working with SharpZipLib and creating AES 256 encrypted zip files /// - public static class SharpZipLibUtils + public static class ZipOutputStreamExtensions { /// - /// Create a to create a AES 256 encrypted zip file + /// The AESKeySize setting for new s /// - /// The input to write to - /// The password to be used to protect the data - /// The created - public static ZipOutputStream CreateZipOutputStream(Stream inputStream, string password) - { - var zipStream = new ZipOutputStream(inputStream); - zipStream.Password = password; - zipStream.IsStreamOwner = true; // underlying streams will be forcibly closed - - return zipStream; - } + private const int AESKeySize = 256; /// /// Add a and add it to a @@ -54,7 +44,7 @@ public static ZipOutputStream CreateZipOutputStream(Stream inputStream, string p /// The /// The input from which to create the /// The name of the entry, including (sub)folder information - public static void AddEntryFromStream(ZipOutputStream zipOutputStream, Stream stream, string name) + public static void AddEntryFromStream(this ZipOutputStream zipOutputStream, Stream stream, string name) { if (stream.Length == 0) { @@ -63,7 +53,7 @@ public static void AddEntryFromStream(ZipOutputStream zipOutputStream, Stream st var entry = new ZipEntry(name) { - AESKeySize = 256, // Set AES encryption to 256 bits for each individual entry + AESKeySize = AESKeySize, // Set AES encryption for each individual entry }; zipOutputStream.PutNextEntry(entry); @@ -79,11 +69,11 @@ public static void AddEntryFromStream(ZipOutputStream zipOutputStream, Stream st /// The /// The location of the file to add /// The location (fullname) of the file to create in the , including (sub)folder information - public static void AddEntryFromFile(ZipOutputStream zipOutputStream, string extraFile, string entryLocation) + public static void AddEntryFromFile(this ZipOutputStream zipOutputStream, string extraFile, string entryLocation) { var entry = new ZipEntry(entryLocation) { - AESKeySize = 256, // Set AES encryption to 256 bits + AESKeySize = AESKeySize, // Set AES encryption for each individual entry }; zipOutputStream.PutNextEntry(entry); diff --git a/CDP4Dal/CDP4Dal.csproj b/CDP4Dal/CDP4Dal.csproj index bc5c9575..cc693e52 100644 --- a/CDP4Dal/CDP4Dal.csproj +++ b/CDP4Dal/CDP4Dal.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 README.md diff --git a/CDP4DalCommon/CDP4DalCommon.csproj b/CDP4DalCommon/CDP4DalCommon.csproj index 171811c7..65793335 100644 --- a/CDP4DalCommon/CDP4DalCommon.csproj +++ b/CDP4DalCommon/CDP4DalCommon.csproj @@ -21,7 +21,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 README.md true diff --git a/CDP4JsonFileDal/JsonFileDal.cs b/CDP4JsonFileDal/JsonFileDal.cs index d4cdd255..6780ecad 100644 --- a/CDP4JsonFileDal/JsonFileDal.cs +++ b/CDP4JsonFileDal/JsonFileDal.cs @@ -34,7 +34,6 @@ namespace CDP4JsonFileDal using CDP4Common.CommonData; using CDP4Common.Comparers; - using CDP4Common.Encryption; using CDP4Common.EngineeringModelData; using CDP4Common.Exceptions; using CDP4Common.Extensions; @@ -56,7 +55,10 @@ namespace CDP4JsonFileDal using NLog; + using Alias = CDP4Common.DTO.Alias; + using Definition = CDP4Common.DTO.Definition; using File = System.IO.File; + using HyperLink = CDP4Common.DTO.HyperLink; using Person = CDP4Common.SiteDirectoryData.Person; using SiteDirectory = CDP4Common.SiteDirectoryData.SiteDirectory; using Thing = CDP4Common.DTO.Thing; @@ -311,7 +313,7 @@ public override Task> Write(IEnumerable o { var password = this.Session.Credentials.Password; - using (var zipArchive = SharpZipLibUtils.CreateZipOutputStream(file, password)) + using (var zipArchive = file.CreateEncryptableZipOutputStream(password)) { this.WriteHeaderToZipFile(exchangeFileHeader, zipArchive); @@ -499,7 +501,7 @@ public override async Task> Read(T thing, CancellationToke } // make sure that the uri is of the correct format - UriExtensions.AssertUriIsFileSchema(this.Credentials.Uri); + this.Credentials.Uri.AssertUriIsFileSchema(); var filePath = this.Credentials.Uri.LocalPath; @@ -657,9 +659,7 @@ private List RetrieveDomainOfExpertiseThings(CDP4Common.DTO.DomainOfExper foreach (var refThing in domain.Alias.ToList()) { - var thingDto = siteDirectoryData.FirstOrDefault(s => s.Iid.Equals(refThing)) as CDP4Common.DTO.Alias; - - if (thingDto != null) + if (siteDirectoryData.FirstOrDefault(s => s.Iid.Equals(refThing)) is Alias thingDto) { thingDto.ExcludedPerson.Clear(); thingDto.ExcludedDomain.Clear(); @@ -673,9 +673,7 @@ private List RetrieveDomainOfExpertiseThings(CDP4Common.DTO.DomainOfExper foreach (var refThing in domain.HyperLink.ToList()) { - var thingDto = siteDirectoryData.FirstOrDefault(s => s.Iid.Equals(refThing)) as CDP4Common.DTO.HyperLink; - - if (thingDto != null) + if (siteDirectoryData.FirstOrDefault(s => s.Iid.Equals(refThing)) is HyperLink thingDto) { thingDto.ExcludedPerson.Clear(); thingDto.ExcludedDomain.Clear(); @@ -692,9 +690,7 @@ private List RetrieveDomainOfExpertiseThings(CDP4Common.DTO.DomainOfExper foreach (var refThing in domain.Definition.ToList()) { - var thingDto = siteDirectoryData.FirstOrDefault(s => s.Iid.Equals(refThing)) as CDP4Common.DTO.Definition; - - if (thingDto != null) + if (siteDirectoryData.FirstOrDefault(s => s.Iid.Equals(refThing)) is Definition thingDto) { thingDto.ExcludedDomain.Clear(); thingDto.ExcludedPerson.Clear(); @@ -903,7 +899,7 @@ public override async Task> Open(Credentials credentials, Can } // make sure that the uri is of the correct format - UriExtensions.AssertUriIsFileSchema(credentials.Uri); + credentials.Uri.AssertUriIsFileSchema(); var filePath = credentials.Uri.LocalPath; @@ -1055,7 +1051,7 @@ private void WriteHeaderToZipFile(ExchangeFileHeader echExchangeFileHeader, ZipO using (var memoryStream = new MemoryStream()) { this.Serializer.SerializeToStream(echExchangeFileHeader, memoryStream); - SharpZipLibUtils.AddEntryFromStream(zipArchive, memoryStream, "Header.json"); + zipArchive.AddEntryFromStream(memoryStream, "Header.json"); } } @@ -1076,7 +1072,7 @@ private void WriteSiteDirectoryToZipFile(IEnumerable prunedSiteDirectoryC this.Serializer.SerializeToStream(orderedContents, memoryStream); - SharpZipLibUtils.AddEntryFromStream(zipOutputStream, memoryStream, "SiteDirectory.json"); + zipOutputStream.AddEntryFromStream(memoryStream, "SiteDirectory.json"); } } @@ -1129,7 +1125,7 @@ private void WriteSiteReferenceDataLibraryToZipFile(Dictionary> using (var memoryStream = new MemoryStream()) { this.Serializer.SerializeToStream(new[] { engineeringModelDto }, memoryStream); - SharpZipLibUtils.AddEntryFromStream(zipOutputStream, memoryStream, engineeringModelFilename); + zipOutputStream.AddEntryFromStream(memoryStream, engineeringModelFilename); } engineeringModels.Add(engineeringModel); @@ -1252,7 +1248,7 @@ private void WriteIterationsToZipFile(Dictionary> { this.Serializer.SerializeToStream(iteration.Value, memoryStream); - SharpZipLibUtils.AddEntryFromStream(zipOutputStream, memoryStream, iterationFilename); + zipOutputStream.AddEntryFromStream(memoryStream, iterationFilename); } } } @@ -1274,7 +1270,7 @@ private void WriteExtensionFilesToZipFile(IEnumerable extraFilesPath, Zi var extraFileName = Path.GetFileName(extraFile); var entryLocation = Path.Combine(ExtensionsZipLocation, extraFileName); - SharpZipLibUtils.AddEntryFromFile(zipOutputStream, extraFile, entryLocation); + zipOutputStream.AddEntryFromFile(extraFile, entryLocation); } } diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index 0663678e..e962e55d 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 JSON LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 README.md diff --git a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj index 16683b90..b1e8cf8a 100644 --- a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj +++ b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 MessagePack LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 [Update] To MessagePack 2.5.187 README.md diff --git a/CDP4Reporting/CDP4Reporting.csproj b/CDP4Reporting/CDP4Reporting.csproj index 71104e9f..687103b2 100644 --- a/CDP4Reporting/CDP4Reporting.csproj +++ b/CDP4Reporting/CDP4Reporting.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 latest README.md diff --git a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj index 06fe624a..8427ceea 100644 --- a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj +++ b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 README.md diff --git a/CDP4Rules/CDP4Rules.csproj b/CDP4Rules/CDP4Rules.csproj index 0e78f0b7..ad35b2c5 100644 --- a/CDP4Rules/CDP4Rules.csproj +++ b/CDP4Rules/CDP4Rules.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 README.md diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj index 4f1f21e3..d75880e1 100644 --- a/CDP4ServicesDal/CDP4ServicesDal.csproj +++ b/CDP4ServicesDal/CDP4ServicesDal.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 README.md diff --git a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj index 7a6e3388..b8bb41d1 100644 --- a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj +++ b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 README.md latest diff --git a/CDP4Web/CDP4Web.csproj b/CDP4Web/CDP4Web.csproj index 5a17cc2e..d81e648c 100644 --- a/CDP4Web/CDP4Web.csproj +++ b/CDP4Web/CDP4Web.csproj @@ -21,7 +21,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 [Update] to Microsoft.Extensions.Logging.Abstractions 8.0.2 README.md diff --git a/CDP4WspDal/CDP4WspDal.csproj b/CDP4WspDal/CDP4WspDal.csproj index fa67b4c7..19325e3d 100644 --- a/CDP4WspDal/CDP4WspDal.csproj +++ b/CDP4WspDal/CDP4WspDal.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.3.5 + [BUMP] To CDP4Common 27.4.0 README.md