Example #1
0
        public static async Task<ObjectWriteResult> CreateTempFile(ObjectType type, int length, byte[] data, string rootPath)
        {
            var name = Path.Combine(rootPath, "tmp" + _random.Next(0, int.MaxValue));
            
            using (var file = File.OpenWrite(name))
            using (var stream = CompressionStream.CompressStream(file))
            using (var md = new MessageDigest())
            {
                var header = Encoding.ASCII.GetBytes(string.Format("{0} {1}\0", type.ToTypeCode(), length));

                await stream.WriteAsync(header, 0, header.Length);
                await stream.WriteAsync(data, 0, data.Length);

                md.Update(header);
                md.Update(data);

                var digest = md.Digest();

                return new ObjectWriteResult
                {
                    FileInfo = new FileInfo(name),
                    ObjectId = Helper.ByteArrayToId(digest)
                };
            }
        }
Example #2
0
 /// <summary>
 /// Gets the result of a calculation that has a simple input.
 /// </summary>
 /// <param name="input">The input.</param>
 /// <returns></returns>
 public static byte[] Digest(byte[] input)
 {
     using (var me = new MessageDigest())
     {
         me.Update(input);
         return me.Digest();
     }
 }
Example #3
0
        public static string ComputeId(Blob blob)
        {
            using (var md = new MessageDigest())
            {
                byte[] data = Encoding.Default.GetBytes(string.Format("blob {0}\0", blob.Size));

                md.Update(data);
                md.Update(blob.Data);

                var digest = md.Digest();

                return Helper.ByteArrayToId(digest);
            }
        }