예제 #1
0
        public void TestHasher()
        {
            // Using flawed MD5 algorithm FOR TEST PURPOSES ONLY
            IIonHasherProvider hasherProvider = new CryptoIonHasherProvider("MD5");
            IIonHasher         hasher         = hasherProvider.NewHasher();

            byte[] emptyHasherDigest = hasher.Digest();

            hasher.Update(new byte[] { 0x0f });
            byte[] digest   = hasher.Digest();
            byte[] expected =
            {
                0xd8, 0x38, 0x69, 0x1e, 0x5d, 0x4a, 0xd0, 0x68, 0x79,
                0xca, 0x72, 0x14, 0x42, 0xe8, 0x83, 0xd4
            };
            TestUtil.AssertEquals(expected, digest, "Digest don't match.");

            // Verify that the hasher resets after digest.
            TestUtil.AssertEquals(emptyHasherDigest, hasher.Digest(), "Digest don't match.");
        }
예제 #2
0
        internal void StepIn(IIonHashValue ionValue)
        {
            IIonHasher hashFunction = this.currentHasher.HashFunction;

            if (this.currentHasher is StructSerializer)
            {
                hashFunction = this.hasherProvider.NewHasher();
            }

            if (ionValue.CurrentType == IonType.Struct)
            {
                this.currentHasher = new StructSerializer(hashFunction, this.Depth(), this.hasherProvider);
            }
            else
            {
                this.currentHasher = new Serializer(hashFunction, this.Depth());
            }

            this.hasherStack.Push(this.currentHasher);
            this.currentHasher.StepIn(ionValue);
        }
예제 #3
0
 internal Serializer(IIonHasher hashFunction, int depth)
 {
     this.HashFunction = hashFunction;
     this.depth        = depth;
 }
예제 #4
0
 internal StructSerializer(IIonHasher hashFunction, int depth, IIonHasherProvider hashFunctionProvider)
     : base(hashFunction, depth)
 {
     this.scalarSerializer = new Serializer(hashFunctionProvider.NewHasher(), depth + 1);
     this.fieldHashes      = new List <byte[]>();
 }