Beispiel #1
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
            {
                CombinedFingerprints scanned = CombinedFingerprints.Parser.ParseFrom(scannedFingerprintData);

                if (scanned.RemoteFingerprintOneofCase == CombinedFingerprints.RemoteFingerprintOneofOneofCase.None ||
                    scanned.LocalFingerprintOneofCase == CombinedFingerprints.LocalFingerprintOneofOneofCase.None ||
                    scanned.VersionOneofCase == CombinedFingerprints.VersionOneofOneofCase.None ||
                    scanned.Version != _fingerprints.Version)
                {
                    throw new FingerprintVersionMismatchException((int)scanned.Version, Version);
                }

                return(ByteUtil.IsEqual(_fingerprints.LocalFingerprint.Content.ToByteArray(), scanned.RemoteFingerprint.Content.ToByteArray()) &&
                       ByteUtil.IsEqual(_fingerprints.RemoteFingerprint.Content.ToByteArray(), scanned.LocalFingerprint.Content.ToByteArray()));
            }
            catch (InvalidProtocolBufferException e)
            {
                throw new FingerprintParsingException(e);
            }
        }
Beispiel #2
0
        internal ScannableFingerprint(byte[] localFingerprintData, byte[] remoteFingerprintData)
        {
            LogicalFingerprint localFingerprint = new LogicalFingerprint
            {
                Content = ByteString.CopyFrom(ByteUtil.Trim(localFingerprintData, 32))
            };

            LogicalFingerprint remoteFingerprint = new LogicalFingerprint
            {
                Content = ByteString.CopyFrom(ByteUtil.Trim(remoteFingerprintData, 32))
            };

            _fingerprints = new CombinedFingerprints
            {
                Version           = (uint)Version,
                LocalFingerprint  = localFingerprint,
                RemoteFingerprint = remoteFingerprint
            };
        }