/// <summary>
        ///     Create and verify publications file instance from stream and with given buffer size.
        /// </summary>
        /// <param name="stream">publications file stream</param>
        /// <param name="bufferSize">buffer size</param>
        /// <returns>publications file</returns>
        public IPublicationsFile Create(Stream stream, int bufferSize)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            Logger.Debug("Creating publications file.");

            byte[] data      = new byte[PublicationsFile.FileBeginningMagicBytes.Length];
            int    bytesRead = stream.Read(data, 0, data.Length);

            if (bytesRead != PublicationsFile.FileBeginningMagicBytes.Length || !Util.IsArrayEqual(data, PublicationsFile.FileBeginningMagicBytes))
            {
                throw new PublicationsFileException("Publications file header is incorrect. Invalid publications file magic bytes.");
            }

            using (MemoryStream memoryStream = new MemoryStream())
            {
                byte[] buffer = new byte[bufferSize];
                while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    memoryStream.Write(buffer, 0, bytesRead);
                }

                PublicationsFile publicationsFile = new PublicationsFile(new RawTag(0x0, false, false, memoryStream.ToArray()));

                try
                {
                    Verify(publicationsFile);
                }
                catch (PkiVerificationException e)
                {
                    Logger.Warn("Publications file verification failed. {0}", e);
                    throw new PublicationsFileException("Publications file verification failed.", e);
                }

                Logger.Debug("Publications file created.");

                return(publicationsFile);
            }
        }
 private void Verify(PublicationsFile publicationsFile)
 {
     _pkiTrustProvider.Verify(publicationsFile.GetSignedBytes(), publicationsFile.GetSignatureValue());
 }