public IFileProtectResponse GetProtectedFile(ContentManagementFlags contentManagementFlags, string fileType, byte[] fileBytes)
        {
            var response = new FileProtectResponse {
                ProtectedFile = Enumerable.Empty <byte>().ToArray()
            };

            var glasswallConfiguration = _glasswallConfigurationAdaptor.Adapt(contentManagementFlags);
            var configurationOutcome   = _glasswallFileOperations.SetConfiguration(glasswallConfiguration);

            if (configurationOutcome != EngineOutcome.Success)
            {
                _logger.Log(LogLevel.Error, "Error processing configuration");
                response.Outcome = configurationOutcome;
                return(response);
            }

            var version = _glasswallFileOperations.GetLibraryVersion();

            _logger.LogInformation($"Engine version: {version}");

            var engineOutcome = _glasswallFileOperations.ProtectFile(fileBytes, fileType, out var protectedFile);

            response.Outcome       = engineOutcome;
            response.ProtectedFile = protectedFile;

            if (engineOutcome != EngineOutcome.Success)
            {
                _logger.Log(LogLevel.Error, $"Unable to protect file, reason: {engineOutcome}.");
            }

            return(response);
        }
Exemple #2
0
        public IFileProtectResponse GetProtectedFile(ContentManagementFlags contentManagementFlags, string fileType, byte[] fileBytes)
        {
            var response = new FileProtectResponse {
                ProtectedFile = Enumerable.Empty <byte>().ToArray()
            };

            var glasswallConfiguration = _glasswallConfigurationAdaptor.Adapt(contentManagementFlags);
            var configurationOutcome   = _glasswallFileOperations.SetConfiguration(glasswallConfiguration);

            if (configurationOutcome != EngineOutcome.Success)
            {
                response.Outcome = configurationOutcome;
                return(response);
            }

            var version = _glasswallFileOperations.GetLibraryVersion();

            var engineOutcome = _glasswallFileOperations.ProtectFile(fileBytes, fileType, out var protectedFile);

            response.Outcome       = engineOutcome;
            response.ProtectedFile = protectedFile;

            if (engineOutcome != EngineOutcome.Success)
            {
                response.ErrorMessage = _glasswallFileOperations.GetEngineError();
            }

            return(response);
        }
        public EngineOutcome ProtectFile(byte[] fileContent, string fileType, out byte[] protectedFile)
        {
            if (fileContent == null)
            {
                throw new ArgumentNullException(nameof(fileContent));
            }
            if (fileType == null)
            {
                throw new ArgumentNullException(nameof(fileType));
            }

            return(_glasswallFileOperations.ProtectFile(fileContent, fileType, out protectedFile));
        }