コード例 #1
0
ファイル: BlockEncoder.cs プロジェクト: Hedzer/Urchin
        public void EncodeBlock()
        {
            BlockEncoder instance = new BlockEncoder(new KeyScheduler {
                Key = Key, IV = IV
            });

            byte[] block   = hasher.ComputeHash(Key);
            byte[] encoded = instance.Encode(block, iterations: 1);
            CollectionAssert.AreNotEqual(encoded, block);
        }
コード例 #2
0
        public void EncodeDecodeBlock()
        {
            BlockEncoder encoder = new BlockEncoder();
            Hash         hash    = new Hash();
            Block        block   = new Block(1, hash);

            var result = encoder.Decode(encoder.Encode(block));

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Number);
            Assert.AreEqual(hash, result.ParentHash);
        }
コード例 #3
0
ファイル: BlockEncoder.cs プロジェクト: Hedzer/Urchin
        public void DecodeBlock()
        {
            BlockEncoder encoder = new BlockEncoder(new KeyScheduler {
                Key = Key, IV = IV
            });
            BlockEncoder decoder = new BlockEncoder(new KeyScheduler {
                Key = Key, IV = IV
            });

            byte[] block   = hasher.ComputeHash(Key);
            byte[] encoded = encoder.Encode(block, iterations: 1);
            byte[] decoded = decoder.Decode(block, iterations: 1);
        }
コード例 #4
0
        void Encode_zero_blocks()
        {
            string errorMessage;

            errorMessage = BlockEncoder.Encode(16, new InstructionBlock[0], BlockEncoderOptions.None);
            Assert.Null(errorMessage);

            errorMessage = BlockEncoder.Encode(32, new InstructionBlock[0], BlockEncoderOptions.None);
            Assert.Null(errorMessage);

            errorMessage = BlockEncoder.Encode(64, new InstructionBlock[0], BlockEncoderOptions.None);
            Assert.Null(errorMessage);
        }
コード例 #5
0
        public void EncodeDecodeBlockWithTransaction()
        {
            BlockEncoder encoder     = new BlockEncoder();
            Address      from        = new Address();
            Address      to          = new Address();
            Transaction  transaction = new Transaction(from, to, new BigInteger(2));

            Block original = new Block(0, null, new Transaction[] { transaction });
            Block block    = encoder.Decode(encoder.Encode(original));

            Assert.IsNotNull(block.Transactions);
            Assert.AreEqual(1, block.Transactions.Count);

            Transaction result = block.Transactions.First();

            Assert.AreEqual(new BigInteger(2), result.Value);
        }
コード例 #6
0
        void Encode_zero_instructions()
        {
            string errorMessage;
            var    codeWriter = new CodeWriterImpl();

            errorMessage = BlockEncoder.Encode(16, new InstructionBlock(codeWriter, Array.Empty <Instruction>(), 0, Array.Empty <RelocInfo>(), Array.Empty <uint>(), Array.Empty <ConstantOffsets>()), BlockEncoderOptions.None);
            Assert.Null(errorMessage);
            Assert.Empty(codeWriter.ToArray());

            errorMessage = BlockEncoder.Encode(32, new InstructionBlock(codeWriter, Array.Empty <Instruction>(), 0, Array.Empty <RelocInfo>(), Array.Empty <uint>(), Array.Empty <ConstantOffsets>()), BlockEncoderOptions.None);
            Assert.Null(errorMessage);
            Assert.Empty(codeWriter.ToArray());

            errorMessage = BlockEncoder.Encode(64, new InstructionBlock(codeWriter, Array.Empty <Instruction>(), 0, Array.Empty <RelocInfo>(), Array.Empty <uint>(), Array.Empty <ConstantOffsets>()), BlockEncoderOptions.None);
            Assert.Null(errorMessage);
            Assert.Empty(codeWriter.ToArray());
        }
コード例 #7
0
ファイル: BlockEncoder.cs プロジェクト: Hedzer/Urchin
        public void Encode()
        {
            List <string> results = new List <string>()
            {
            };

            for (int i = CryptoTransform.MinRounds; i < CryptoTransform.MinRounds + CryptoTransform.MaxAdditionalRounds; i++)
            {
                BlockEncoder instance = new BlockEncoder(new KeyScheduler {
                    Key = Key, IV = IV
                });
                byte[] block   = hasher.ComputeHash(Key);
                byte[] encoded = instance.Encode(block, iterations: i);
                Assert.IsTrue(block.Length == encoded.Length);
                results.Add(Encoding.ASCII.GetString(encoded));
            }
            CollectionAssert.AllItemsAreUnique(results);
        }
コード例 #8
0
ファイル: BlockEncoder.cs プロジェクト: Hedzer/Urchin
 public void Decode()
 {
     for (int i = CryptoTransform.MinRounds; i < CryptoTransform.MinRounds + CryptoTransform.MaxAdditionalRounds; i++)
     {
         BlockEncoder encoder = new BlockEncoder(new KeyScheduler {
             Key = Key, IV = IV
         });
         BlockEncoder decoder = new BlockEncoder(new KeyScheduler {
             Key = Key, IV = IV
         });
         byte[] block   = hasher.ComputeHash(Key);
         byte[] copy    = (byte[])block.Clone();
         byte[] encoded = encoder.Encode(block, i);
         //check to see whether it's being altered by accident
         CollectionAssert.AreEqual(copy, block);
         byte[] decoded = decoder.Decode(encoded, i);
         Assert.IsTrue(block.Length == decoded.Length);
         CollectionAssert.AreEqual(decoded, block);
     }
 }
コード例 #9
0
        void DefaultArgs()
        {
            const int   bitness = 64;
            const ulong origRip = 0x123456789ABCDE00;
            const ulong newRip  = 0x8000000000000000;

            var originalData = new byte[] {
                /*0000*/ 0xB0, 0x00,                   // mov al,0
                /*0002*/ 0xEB, 0x09,                   // jmp short 123456789ABCDE0Dh
                /*0004*/ 0xB0, 0x01,                   // mov al,1
                /*0006*/ 0xE9, 0x03, 0x00, 0x00, 0x00, // jmp near ptr 123456789ABCDE0Eh
                /*000B*/ 0xB0, 0x02,                   // mov al,2
            };
            var instructions = BlockEncoderTest.Decode(bitness, origRip, originalData, DecoderOptions.None);
            var codeWriter   = new CodeWriterImpl();
            var errorMessage = BlockEncoder.Encode(bitness, new InstructionBlock(codeWriter, instructions, newRip));

            Assert.Null(errorMessage);
            Assert.Equal(0x28, codeWriter.ToArray().Length);
        }
コード例 #10
0
 void Invalid_ConstantOffsets_Throws()
 {
     Assert.Throws <ArgumentException>(() => BlockEncoder.Encode(64, new InstructionBlock(new CodeWriterImpl(), new Instruction[0], 0, Array.Empty <RelocInfo>(), null, new ConstantOffsets[1]), BlockEncoderOptions.None));
     Assert.Throws <ArgumentException>(() => BlockEncoder.Encode(64, new InstructionBlock(new CodeWriterImpl(), new Instruction[1], 0, Array.Empty <RelocInfo>(), null, new ConstantOffsets[0]), BlockEncoderOptions.None));
 }