コード例 #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);
            }
        }
コード例 #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))
            };

            this.fingerprints = new CombinedFingerprints
            {
                Version           = (uint)VERSION,
                LocalFingerprint  = localFingerprint,
                RemoteFingerprint = remoteFingerprint
            };
        }