示例#1
0
        public void GetChainHeadTest()
        {
            var val       = Strings.DecodeHexIntoBytes("475fbcef5e3a4e1621ed9a6fda5840c1d654715e55a8f5e514af0fb879ce0aec");
            var chainHead = Chain.GetChainHead(val);

            Assert.IsFalse(Bytes.Equality(chainHead.ChainHead, Encoding.UTF8.GetBytes("4c195ddcba466d2e15ce29d150c985bd7aaadaf881fa9a0abca0ee6ab07159f7")));
        }
示例#2
0
        public void TestSegmentize()
        {
            var data = new byte[70000];
            var r    = new Random();

            r.NextBytes(data);

            var s       = DataSegment.Segmentize(data, firstSegmentLength: DataSegment.DefaultMaxSegmentLength - 512);
            var outData = DataSegment.Desegmentize(s);

            Assert.IsTrue(Bytes.Equality(data, outData), "Pre and post segmentation data does not match");
        }
示例#3
0
        /// <summary>
        ///     Unpack storable data to a CandidateOldVersionRecord
        /// </summary>
        /// <param name="packed">The packed OldVersionRecord data</param>
        /// <param name="pubKey">The public key to verify with</param>
        /// <returns>The record object</returns>
        public static CandidateOldVersionRecord Unpack(byte[] packed, RSAParameters pubKey)
        {
            var sig    = Arrays.CopyOfRange(packed, packed.Length - 512, packed.Length);
            var data   = Arrays.CopyOfRange(packed, 0, packed.Length - 512);
            var prefix = Arrays.CopyOfRange(packed, 0, CandidateOldVersionPrefix.Length);

            if (!Crypto.RSA_Verify(data, sig, pubKey))
            {
                throw new DataVerifyException("Could not cryptographically verify candidate update record");
            }

            data = Arrays.CopyOfRange(data, CandidateOldVersionPrefix.Length, data.Length);

            if (!Bytes.Equality(CandidateOldVersionPrefix, prefix) ||
                packed.Length != ChainIdLength * 2 + 512 + CandidateOldVersionPrefix.Length)
            {
                throw new RecordDataInvalidException("Invalid data provided for packed candidate update record");
            }

            return(new CandidateOldVersionRecord(Arrays.CopyOfRange(data, 0, ChainIdLength),
                                                 Arrays.CopyOfRange(data, ChainIdLength, ChainIdLength * 2)));
        }