newMessageDigest() 공개 정적인 메소드

Create a new digest function for objects.
public static newMessageDigest ( ) : MessageDigest
리턴 MessageDigest
예제 #1
0
        public ObjectId computeName()
        {
            MessageDigest md = Constants.newMessageDigest();

            foreach (ObjectToPack otp in sortByName())
            {
                otp.copyRawTo(_buf, 0);
                md.Update(_buf, 0, Constants.OBJECT_ID_LENGTH);
            }
            return(ObjectId.FromRaw(md.Digest()));
        }
예제 #2
0
 public PackOutputStream(Stream stream)
 {
     _crc    = new Crc32();
     _md     = Constants.newMessageDigest();
     _stream = stream;
 }
예제 #3
0
        ///	<summary>
        /// Write content of index to disk.
        ///	</summary>
        ///	<exception cref="IOException"> </exception>
        public void write()
        {
            CheckWriteOk();
            var tmpIndex = new FileInfo(_cacheFile.FullName + ".tmp");
            var @lock    = new FileInfo(_cacheFile.FullName + ".lock");

            try
            {
                using (@lock.Create())
                {
                }
            }
            catch (IOException)
            {
                throw new IOException("Index file is in use");
            }

            try
            {
                using (var fileOutputStream = new FileStream(tmpIndex.FullName, System.IO.FileMode.CreateNew))
                    using (var writer = new EndianBinaryWriter(new BigEndianBitConverter(), fileOutputStream))
                    {
                        MessageDigest newMessageDigest = Constants.newMessageDigest();
                        var           ms = new MemoryStream();

                        _header = new Header(_entries.Values as ICollection);
                        _header.Write(ms);

                        newMessageDigest.Update(ms.ToArray());
                        writer.Write(ms.ToArray());

                        foreach (Entry entry in _entries.Values)
                        {
                            ms = new MemoryStream();

                            entry.Write(ms);
                            newMessageDigest.Update(ms.ToArray());
                            writer.Write(ms.ToArray());
                        }

                        ms = new MemoryStream();

                        byte[] digestBuffer = newMessageDigest.Digest();
                        ms.Write(digestBuffer, 0, digestBuffer.Length);
                        writer.Write(ms.ToArray(), 0, digestBuffer.Length);
                    }

                _cacheFile.Refresh();
                if (_cacheFile.Exists)
                {
                    try
                    {
                        _cacheFile.Delete();
                    }
                    catch (IOException)
                    {
                        throw new IOException("Could not rename delete old index");
                    }
                }

                if (!tmpIndex.RenameTo(_cacheFile.FullName))
                {
                    throw new IOException("Could not rename temporary index file to index");
                }

                _changed   = false;
                _statDirty = false;
                _cacheFile.Refresh();
                _lastCacheTime = _cacheFile.lastModified();
                Repository.fireIndexChanged();
            }
            finally
            {
                try
                {
                    @lock.Delete();
                }
                catch (IOException)
                {
                    throw new IOException("Could not delete lock file. Should not happen");
                }

                try
                {
                    tmpIndex = new FileInfo(_cacheFile.FullName + ".tmp");
                    if (tmpIndex.Exists)
                    {
                        tmpIndex.Delete();
                    }
                }
                catch (Exception)
                {
                    throw new IOException("Could not delete temporary index file. Should not happen");
                }
            }
        }
예제 #4
0
 ///	<summary>
 /// Construct an object writer for the specified repository.
 /// </summary>
 ///	<param name="repo"> </param>
 public ObjectWriter(Repository repo)
 {
     _r   = repo;
     _buf = new byte[0x2000];
     _md  = Constants.newMessageDigest();
 }