Esempio n. 1
0
        public async Task ParseAsync(CancellationToken cancellation)
        {
            _disposed = true;
            using (var sr = new StreamReader(_config, Encoding.UTF8))
                using (var md5 = MD5.Create())
                {
                    md5.TransformBlock(ByteOrderMark, 0, ByteOrderMark.Length, null, 0);
                    string        previous = null;
                    OmmConfHeader header   = null;
                    while (!sr.EndOfStream)
                    {
                        var current = await sr.ReadLineAsync().ConfigureAwait(false);

                        if (current.Length == 0)
                        {
                            //new section
                            header = null;
                        }
                        else if (current.AsSpan().TrimStart('-').IsEmpty)
                        {
                            if (previous is null)
                            {
                                throw new InvalidDataException("omm_conf cannot start with separator line ---");
                            }
                            header = new OmmConfHeader(previous.Split('|'));
                        }
                        else if (!(header is null))
                        {
                            var values  = current.Split('|');
                            var data    = new OmmConfEntry(header, values);
                            var section = AddSection(data.Type);
                            section.Add(data);
                        }
                        if (previous != null)
                        {
                            var bytes = Encoding.UTF8.GetBytes(previous);
                            md5.TransformBlock(bytes, 0, bytes.Length, null, 0);
                            md5.TransformBlock(LineBreak, 0, LineBreak.Length, null, 0);
                        }
                        previous = current;
                    }
                    md5.TransformFinalBlock(HiddenMd5Data, 0, HiddenMd5Data.Length);
                    var checksum = HexEncoding.ByteToHex(md5.Hash);
                    if (previous != checksum)
                    {
                        throw new InvalidDataException("invalid checksum");
                    }
                }
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor for hex key
 /// </summary>
 /// <param name="hexKey">Cipher key as a hex string</param>
 public BlowFish(string hexKey)
     : this(HexEncoding.HexToByte(hexKey))
 {
 }