Пример #1
0
        public static bool TryUnpack(CookieProvider cookieProvider, byte[] buf, int size, out PeerToPeerRequest packet)
        {
            if (size < CookieProvider.CookieSize + 7 || !cookieProvider.Check(buf, 7, out var cookie))
            {
                packet = default;
                return(false);
            }

            int  offest       = 1;
            var  id           = BinaryUtil.ReadInt(buf, ref offest);
            byte majorVersion = buf[offest++];
            byte minorVersion = buf[offest++];

            packet = new PeerToPeerRequest(id, majorVersion, minorVersion, cookie);
            return(true);
        }
Пример #2
0
        public static bool TryUnpack(CookieProvider cookieProvider, RSA rsa, byte[] buf, int size, out HandshakeRequest packet)
        {
            if (size < CookieProvider.CookieSize + 3 || !cookieProvider.Check(buf, 3, out var cookie))
            {
                packet = default;
                return(false);
            }

            int  offest       = 1;
            byte majorVersion = buf[offest++];
            byte minorVersion = buf[offest++];

            var payload = new byte[size - (CookieProvider.CookieSize + 3)];

            Buffer.BlockCopy(buf, CookieProvider.CookieSize + 3, payload, 0, payload.Length);

            if (rsa != null)
            {
                payload = rsa.Decrypt(payload, RSAEncryptionPadding.Pkcs1);
            }

            packet = new HandshakeRequest(majorVersion, minorVersion, cookie, payload);
            return(true);
        }