Exemple #1
0
        public void SerializeAndReadBack()
        {
            var registry = new DependencyFingerprintProtocolRegistry();

            registry.Register <CombinedFingerprintProtocol>();
            registry.Register <SourceSetFingerprintProtocol>();

            var ser = new BinarySerializer(registry);
            var dep = CreateDependencyObject();
            var fp1 = dep.Fingerprint;

            byte[] data;
            using (var ms = new MemoryStream())
            {
                fp1.Save(ser, ms);
                data = ms.ToArray();
            }

            CombinedFingerprint fp2;

            using (var ms = new MemoryStream(data))
            {
                fp2 = new CombinedFingerprint(ser, ms);
            }

            fp1.Should().Be(fp2);
        }
Exemple #2
0
        /**
         * Compare a scanned QR code with what we expect.
         *
         * @param scannedFingerprintData The scanned data
         * @return True if matching, otehrwise false.
         * @throws FingerprintVersionMismatchException if the scanned fingerprint is the wrong version.
         * @throws FingerprintIdentifierMismatchException if the scanned fingerprint is for the wrong stable identifier.
         */
        public bool compareTo(byte[] scannedFingerprintData)

        /* throws FingerprintVersionMismatchException,
         *     FingerprintIdentifierMismatchException,
         *     FingerprintParsingException */
        {
            try
            {
                CombinedFingerprint scannedFingerprint = CombinedFingerprint.ParseFrom(scannedFingerprintData);

                if (!scannedFingerprint.HasRemoteFingerprint || !scannedFingerprint.HasLocalFingerprint ||
                    !scannedFingerprint.HasVersion || scannedFingerprint.Version != combinedFingerprint.Version)
                {
                    throw new FingerprintVersionMismatchException();
                }

                if (!combinedFingerprint.LocalFingerprint.Identifier.Equals(scannedFingerprint.RemoteFingerprint.Identifier) ||
                    !combinedFingerprint.RemoteFingerprint.Identifier.Equals(scannedFingerprint.LocalFingerprint.Identifier))
                {
                    throw new FingerprintIdentifierMismatchException(combinedFingerprint.LocalFingerprint.Identifier.ToStringUtf8(),
                                                                     combinedFingerprint.RemoteFingerprint.Identifier.ToStringUtf8(),
                                                                     scannedFingerprint.LocalFingerprint.Identifier.ToStringUtf8(),
                                                                     scannedFingerprint.RemoteFingerprint.Identifier.ToStringUtf8());
                }

                return(ByteUtil.isEqual(combinedFingerprint.LocalFingerprint.ToByteArray(), scannedFingerprint.RemoteFingerprint.ToByteArray()) &&
                       ByteUtil.isEqual(combinedFingerprint.RemoteFingerprint.ToByteArray(), scannedFingerprint.LocalFingerprint.ToByteArray()));
            }
            catch (InvalidProtocolBufferException e)
            {
                throw new FingerprintParsingException(e);
            }
        }
        public void SerializeAndReadBack()
        {
            var registry = new DependencyFingerprintProtocolRegistry();
            registry.Register<CombinedFingerprintProtocol>();
            registry.Register<SourceSetFingerprintProtocol>();

            var ser = new BinarySerializer(registry);
            var dep = CreateDependencyObject();
            var fp1 = dep.Fingerprint;

            byte[] data;
            using (var ms = new MemoryStream())
            {
                fp1.Save(ser, ms);
                data = ms.ToArray();
            }

            CombinedFingerprint fp2;
            using (var ms = new MemoryStream(data))
            {
                fp2 = new CombinedFingerprint(ser, ms);
            }

            fp1.Should().Be(fp2);
        }
Exemple #4
0
 public ScannableFingerprint(int version,
                             string localStableIdentifier, IdentityKey localIdentityKey,
                             string remoteStableIdentifier, IdentityKey remoteIdentityKey)
 {
     this.combinedFingerprint = CombinedFingerprint.CreateBuilder()
                                .SetVersion((uint)version)
                                .SetLocalFingerprint(FingerprintData.CreateBuilder()
                                                     .SetIdentifier(ByteString.CopyFrom(Encoding.UTF8.GetBytes(localStableIdentifier)))
                                                     .SetPublicKey(ByteString.CopyFrom(localIdentityKey.serialize())))
                                .SetRemoteFingerprint(FingerprintData.CreateBuilder()
                                                      .SetIdentifier(ByteString.CopyFrom(Encoding.UTF8.GetBytes(remoteStableIdentifier)))
                                                      .SetPublicKey(ByteString.CopyFrom(remoteIdentityKey.serialize())))
                                .Build();
 }
        public void SerializeAndReadBack()
        {
            var ser = new BinarySerializer();
            var dep = CreateDependencyObject();
            var fp1 = dep.CreateFingerprint();

            byte[] data;
            using (var ms = new MemoryStream())
            {
                fp1.Save(ser, ms);
                data = ms.ToArray();
            }

            CombinedFingerprint fp2;

            using (var ms = new MemoryStream(data))
            {
                fp2 = new CombinedFingerprint(ser, ms);
            }

            fp1.Should().Be(fp2);
        }
        public void SerializeAndReadBack()
        {
            var ser = new BinarySerializer();
            var dep = CreateDependencyObject();
            var fp1 = dep.CreateFingerprint();

            byte[] data;
            using (var ms = new MemoryStream())
            {
                fp1.Save(ser, ms);
                data = ms.ToArray();
            }

            CombinedFingerprint fp2;
            using (var ms = new MemoryStream(data))
            {
                fp2 = new CombinedFingerprint(ser, ms);
            }

            fp1.Should().Be(fp2);
        }