Exemplo n.º 1
0
        public void Hash()
        {
            var values = new Dictionary <string, GGValue> {
                { "int", new GGLiteral(42) },
                { "double", new GGLiteral(3.14159) },
                { "string", new GGLiteral("My string") },
                { "array", new GGArray(new GGLiteral(0), new GGLiteral(1)) },
                { "null", new GGLiteral(null) }
            };
            var gHash         = new GGHash(values);
            var actualLiteral = GGParser.Parse(gHash.ToString());

            Assert.Equal(gHash, actualLiteral);
        }
Exemplo n.º 2
0
        public override void Write()
        {
            base.Write();

            byte[] hash;
            if (this.HashType == HashType.GG32)
            {
                hash = GGHash.GG32(this.Password, this.Seed);
            }
            else
            {
                hash = GGHash.SHA1(this.Password, this.Seed);
            }

            byte[] description = UTF8Encoding.UTF8.GetBytes(this.Description);

            this.writer.Write(this.Number);
            this.writer.Write(UTF8Encoding.UTF8.GetBytes(this.Language));
            this.writer.Write((byte)this.HashType);
            this.writer.Write(hash);

            for (int i = 0; i < 64 - hash.Length; ++i)
            {
                this.writer.Write(Byte.MinValue);
            }

            this.writer.Write((uint)this.Status);
            this.writer.Write((uint)this.Channels);
            this.writer.Write((uint)this.Features);
            this.writer.Write(BitConverter.ToUInt32(this.LocalIP.GetAddressBytes(), 0));
            this.writer.Write(this.LocalPort);
            this.writer.Write(BitConverter.ToUInt32(this.ExternalIP.GetAddressBytes(), 0));
            this.writer.Write(this.ExternalPort);
            this.writer.Write(this.ImageSize);
            this.writer.Write(this.Unknown);
            this.writer.Write(this.Client.Length);
            this.writer.Write(UTF8Encoding.UTF8.GetBytes(this.Client));
            this.writer.Write(description.Length);
            this.writer.Write(description);
        }