Example #1
0
        public static Signature Concat(Signature s1, Signature s2)
        {
            if (s1.data == null && s2.data == null)
            {
                return(Signature.Empty);
            }

            if (s1.data == null)
            {
                return(s2);
            }

            if (s2.data == null)
            {
                return(s1);
            }

            if (s1.Length + s2.Length == 0)
            {
                return(Signature.Empty);
            }

            byte[] data = new byte[s1.data.Length + s2.data.Length];
            s1.data.CopyTo(data, 0);
            s2.data.CopyTo(data, s1.data.Length);
            return(Signature.Take(data));
        }
Example #2
0
        public Signature ReadSignature()
        {
            byte ln = ReadByte();

            // Avoid an array allocation for small signatures
            if (ln == 1)
            {
                DType dtype = (DType)ReadByte();
                ReadNull();
                return(new Signature(dtype));
            }

            if (ln > Protocol.MaxSignatureLength)
            {
                throw new Exception("Signature length " + ln + " exceeds maximum allowed " + Protocol.MaxSignatureLength + " bytes");
            }

            byte[] sigData = new byte[ln];
            Array.Copy(data, pos, sigData, 0, (int)ln);
            pos += (int)ln;
            ReadNull();

            return(Signature.Take(sigData));
        }