コード例 #1
0
 /// <summary>
 /// Returns a value that indicates whether this instance and another <see cref="AnimationNode"/> are equal.
 /// </summary>
 /// <param name="other">The other <see cref="AnimationNode"/>.</param>
 /// <returns><see langword="true"/> if the two animation nodes are equals; otherwise, <see langword="false"/>.</returns>
 public bool Equals(AnimationNode other) =>
 _hashcode == other._hashcode &&
 PostState == other.PostState &&
 PreState == other.PreState &&
 MemoryExtensions.SequenceEqual(PositionKeys, other.PositionKeys) &&
 MemoryExtensions.SequenceEqual(RotationKeys, other.RotationKeys) &&
 MemoryExtensions.SequenceEqual(ScalingKeys, other.ScalingKeys);
コード例 #2
0
ファイル: HashesMessage.cs プロジェクト: gweffect/monotorrent
        public override bool Equals(object obj)
        {
            if (!(obj is HashesMessage other))
            {
                return(false);
            }

            if (Hashes.Count != other.Hashes.Count)
            {
                return(false);
            }

            for (int i = 0; i < Hashes.Count; i++)
            {
                if (!MemoryExtensions.SequenceEqual(Hashes[i].Span, other.Hashes[i].Span))
                {
                    return(false);
                }
            }

            return(MemoryExtensions.SequenceEqual(PiecesRoot.Span, other.PiecesRoot.Span) &&
                   BaseLayer == other.BaseLayer &&
                   Index == other.Index &&
                   Length == other.Length &&
                   ProofLayers == other.ProofLayers);
        }
コード例 #3
0
ファイル: NSymbol255.cs プロジェクト: hthubert/DataSpreads
        public bool Equals(NSymbol255 other)
        {
            if (Len != other.Len)
            {
                return(false);
            }

            return(MemoryExtensions.SequenceEqual(AsSpan(), other.AsSpan()));
        }
コード例 #4
0
 public bool Equals(StorageKey other)
 {
     if (other is null)
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Id == other.Id && MemoryExtensions.SequenceEqual <byte>(Key, other.Key));
 }
コード例 #5
0
ファイル: MemorySlice.cs プロジェクト: rhysmdnz/wabbajack
 public static bool Equal <T>(ReadOnlyMemorySlice <T>?lhs, ReadOnlyMemorySlice <T>?rhs)
     where T : IEquatable <T>
 {
     if (lhs == null && rhs == null)
     {
         return(true);
     }
     if (lhs == null || rhs == null)
     {
         return(false);
     }
     return(MemoryExtensions.SequenceEqual(lhs.Value.Span, rhs.Value.Span));
 }
コード例 #6
0
    public static void SyncFolder <T>(ref bool?replace, ref bool?delete, string folder, List <T> should, Func <T, string> fileName, Func <T, XDocument> toXML)
    {
        if (should.Any() && !Directory.Exists(folder))
        {
            Directory.CreateDirectory(folder);
        }

        var deleteLocal  = delete;
        var replaceLocal = replace;

        SafeConsole.WriteLineColor(ConsoleColor.Gray, "Exporting to " + folder);
        Synchronizer.Synchronize(
            newDictionary: should.ToDictionary(fileName),
            oldDictionary: Directory.GetFiles(folder).ToDictionary(a => Path.GetFileName(a)),
            createNew: (fileName, entity) => {
            toXML(entity).Save(Path.Combine(folder, fileName));
            SafeConsole.WriteLineColor(ConsoleColor.Green, " Created " + fileName);
        },
            removeOld: (fileName, fullName) =>
        {
            if (SafeConsole.Ask(ref deleteLocal, "Delete {0}?".FormatWith(fileName)))
            {
                File.Delete(fullName);
                SafeConsole.WriteLineColor(ConsoleColor.Red, " Deleted " + fileName);
            }
        }, merge: (fileName, entity, fullName) =>
        {
            var xml = toXML(entity);

            var newBytes = new MemoryStream().Do(ms => xml.Save(ms)).ToArray();
            var oldBytes = File.ReadAllBytes(fullName);

            if (!MemoryExtensions.SequenceEqual <byte>(newBytes, oldBytes))
            {
                if (SafeConsole.Ask(ref replaceLocal, " Override {0}?".FormatWith(fileName)))
                {
                    xml.Save(Path.Combine(folder, fileName));
                    SafeConsole.WriteLineColor(ConsoleColor.Yellow, " Overriden " + fileName);
                }
            }
            else
            {
                SafeConsole.WriteLineColor(ConsoleColor.DarkGray, " Identical " + fileName);
            }
        });

        delete  = deleteLocal;
        replace = replaceLocal;
    }
コード例 #7
0
ファイル: SafeHandles.cs プロジェクト: vhatuncev/corefx
 internal static bool MemoryCompare(System.IntPtr buf1, System.IntPtr buf2, int count)
 {
     Debug.Assert(buf1 != buf2, "buf1 and buf2 are the same");
     Debug.Assert(buf1.ToInt64() < buf2.ToInt64() || buf2.ToInt64() + count <= buf1.ToInt64(), "overlapping region buf1");
     Debug.Assert(buf2.ToInt64() < buf1.ToInt64() || buf1.ToInt64() + count <= buf2.ToInt64(), "overlapping region buf2");
     Debug.Assert(0 <= count, "negative count");
     unsafe
     {
         ReadOnlySpan <byte> span1 = new ReadOnlySpan <byte>(buf1.ToPointer(), count);
         ReadOnlySpan <byte> span2 = new ReadOnlySpan <byte>(buf2.ToPointer(), count);
         return(!MemoryExtensions.SequenceEqual(span1, span2));
         //0​ if all count bytes of lhs and rhs are equal.
         // TODO: confirm condition with tests
     }
 }
コード例 #8
0
 public bool Equals(Token other)
 {
     if (Kind != other.Kind)
     {
         return(false);
     }
     if (Symbol != other.Symbol)
     {
         return(false);
     }
     if (!MemoryExtensions.SequenceEqual(Text.Span, other.Text.Span))
     {
         return(false);
     }
     return(true);
 }
コード例 #9
0
        public async Task <LoginResponse> MakeAssertion([FromBody][Required] MakeAssertionRequest request)
        {
            using (AuthLogic.Disable())
                using (Transaction tr = new Transaction())
                {
                    var assertionOptions = Database.Retrieve <WebAuthnAssertionOptionsEntity>(request.AssertionOptionsId);
                    var options          = AssertionOptions.FromJson(assertionOptions.Json);

                    var cred = Database.Query <WebAuthnCredentialEntity>().SingleEx(cred => cred.CredentialId == request.AssertionRawResponse.Id);

                    var res = await fido2.MakeAssertionAsync(request.AssertionRawResponse, options, cred.PublicKey, (uint)cred.Counter, (args) =>
                    {
                        if (!MemoryExtensions.SequenceEqual <byte>(cred.CredentialId, args.CredentialId))
                        {
                            return(Task.FromResult(false));
                        }

                        var userId = Encoding.UTF8.GetBytes(cred.User.Id.ToString());
                        if (!MemoryExtensions.SequenceEqual <byte>(userId, args.UserHandle))
                        {
                            return(Task.FromResult(false));
                        }

                        return(Task.FromResult(true));
                    });

                    cred.Counter++;
                    cred.Save();

                    var user = cred.User.RetrieveAndForget();

                    AuthServer.OnUserPreLogin(ControllerContext, user);

                    AuthServer.AddUserSession(ControllerContext, user);

                    var token = AuthTokenServer.CreateToken(user);

                    return(tr.Commit(new LoginResponse {
                        userEntity = user, token = token, authenticationType = "webauthn"
                    }));
                }
        }
コード例 #10
0
        private void RLPListEncodeDecodeTest(int items)
        {
            RLPList list = new RLPList();

            for (int i = 0; i < items; i++)
            {
                if (i % 2 == 0)
                {
                    list.Items.Add(new byte[] { (byte)(i % 256) });
                }
                else
                {
                    list.Items.Add(new RLPList());
                }
            }

            byte[]  encoded = RLP.Encode(list);
            RLPList list2   = (RLPList)RLP.Decode(encoded);

            Assert.Equal(list.Items.Count, list2.Items.Count);

            for (int i = 0; i < list.Items.Count; i++)
            {
                if (i % 2 == 0)
                {
                    Assert.IsType <RLPByteArray>(list2.Items[i]);
                    RLPByteArray b1 = ((RLPByteArray)list.Items[i]);
                    RLPByteArray b2 = ((RLPByteArray)list2.Items[i]);
                    Assert.True(MemoryExtensions.SequenceEqual(b1.Data.Span, b2.Data.Span));
                }
                else
                {
                    Assert.IsType <RLPList>(list2.Items[i]);
                }
            }
        }
コード例 #11
0
 public static void Equal(ReadOnlySpan <byte> actual, ReadOnlySpan <byte> expected) =>
 Xunit.Assert.True(
     MemoryExtensions.SequenceEqual(expected, actual),
     $"Expected does not match actual.\nExpected:\t{SpanToString(expected)}\nActual:\t\t{SpanToString(actual)}"
     );
コード例 #12
0
 public bool Equals(BitVector other) =>
 Length == other.Length &&
 MemoryExtensions.SequenceEqual(new ReadOnlySpan <ulong>(_blocks), new ReadOnlySpan <ulong>(other._blocks));
コード例 #13
0
 public bool Equals(Signature64 other)
 {
     return(MemoryExtensions.SequenceEqual(AsSpan(), other.AsSpan()));
 }
コード例 #14
0
 public bool Equals(Memory <T> x, Memory <T> y)
 {
     return(MemoryExtensions.SequenceEqual(x.Span, y.Span));
 }
コード例 #15
0
 /// <summary>
 /// Returns a value that indicates whether this instance and another <see cref="Animation"/> are equal.
 /// </summary>
 /// <param name="other">The other <see cref="Animation"/>.</param>
 /// <returns><see langword="true"/> if the two animations are equals; otherwise, <see langword="false"/>.</returns>
 public bool Equals(Animation other) =>
 ReferenceEquals(this, other) ||
 (GetHashCode() == other.GetHashCode() &&
  Duration == other.Duration &&
  TicksPerSecond == other.TicksPerSecond &&
  MemoryExtensions.SequenceEqual(Channels, other.Channels));
コード例 #16
0
 public bool Equals(Hash16 other)
 {
     return(MemoryExtensions.SequenceEqual(AsSpan(), other.AsSpan()));
 }
コード例 #17
0
 public bool Equals(UnicodeSequence other)
 {
     return(MemoryExtensions.SequenceEqual <Codepoint>(_codepoints, other._codepoints));
 }