Ejemplo n.º 1
0
        async Task <IDictionary <string, object> > IFileBackend.ChunkedUploadCompleteAsync(
            object context,
            string uploadKey,
            string id,
            IChunkStatus[] chunkStatuses,
            CancellationToken cancellationToken
            )
        {
            var config = context as Context;
            var state  = new SequentialState(chunkStatuses.Last().State);

            // Decode and remove this drivers layer of SequentialState
            for (int i = 0; i < chunkStatuses.Length; i++)
            {
                chunkStatuses[i].State = new SequentialState(chunkStatuses[i].State).NextDriverState;
            }

            var values = await config.NextDriver.ChunkedUploadCompleteAsync(
                config.NextDriverContext, uploadKey, id, chunkStatuses, cancellationToken
                );

            values = values ?? new Dictionary <string, object>();
            ReportDigestValues(values, state);

            return(values);
        }
Ejemplo n.º 2
0
 private void ReportDigestValues(IDictionary <string, object> values, SequentialState state)
 {
     if (state.MD5 != null)
     {
         values.Add("md5", GetDigestValue(state.MD5));
     }
     if (state.SHA1 != null)
     {
         values.Add("sha1", GetDigestValue(state.SHA1));
     }
     if (state.SHA256 != null)
     {
         values.Add("sha256", GetDigestValue(state.SHA256));
     }
 }
Ejemplo n.º 3
0
        async Task <string> IFileBackend.ChunkedUploadChunkAsync(
            object context,
            string id,
            string uploadKey,
            string chunkKey,
            int chunkIndex,
            int totalChunks,
            string sequentialState,
            long from,
            long to,
            long totalLength,
            Stream stream,
            CancellationToken cancellationToken
            )
        {
            var config = context as Context;

            var state   = new SequentialState(sequentialState);
            var digests = PrepareDigests(config, state, isFirstChunk: chunkIndex == 0);

            using (var encryptor = new ChunkEncryptorStreamReader(
                       stream,
                       config.CryptographyAlgorithm,
                       from,
                       to,
                       totalLength,
                       digests,
                       state.IV(),
                       Logger
                       ))
                using (var wrapper = new StreamRequestWrapper(encryptor, encryptor.Length, Logger))
                {
                    state.NextDriverState = await config.NextDriver.ChunkedUploadChunkAsync(
                        config.NextDriverContext, id, uploadKey, chunkKey, chunkIndex, totalChunks,
                        state.NextDriverState,
                        from, to, totalLength, wrapper,
                        cancellationToken
                        );

                    state.IVBase64 = Convert.ToBase64String(encryptor.NextIV());

                    return(state.ToString());
                }
        }
Ejemplo n.º 4
0
        private List <GeneralDigest> PrepareDigests(Context config, SequentialState state, bool isFirstChunk)
        {
            var digests = new List <GeneralDigest>();

            if (config.MD5Enabled)
            {
                digests.Add(state.MD5 = isFirstChunk ? new MD5Digest() : state.MD5);
            }

            if (config.SHA1Enabled)
            {
                digests.Add(state.SHA1 = isFirstChunk ? new Sha1Digest() : state.SHA1);
            }

            if (config.SHA256Enabled)
            {
                digests.Add(state.SHA256 = isFirstChunk ? new Sha256Digest() : state.SHA256);
            }

            return(digests);
        }