A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://rubydoc.info/github/cryptosphere/rbnacl/RbNaCl/KeyComparator below:

KeyComparator – Documentation for cryptosphere/rbnacl (main) – RubyDoc.info

Module: RbNaCl::KeyComparator Overview

Implements comparisons of keys

This permits both timing invariant equality tests, as well as lexicographical sorting.

Instance Method Summary collapse Instance Method Details #<=>(other) ⇒ 0, ...
19
20
21
22
23
24
25
26
27
28
# File 'lib/rbnacl/key_comparator.rb', line 19

def <=>(other)
  if KeyComparator > other.class
    other = other.to_bytes
  elsif other.respond_to?(:to_str)
    other = other.to_str
  else
    return nil
  end
  compare32(other)
end
#==(other) ⇒ true, false

equality operator

The equality operator is explicity defined, despite including Comparable and having a spaceship operator, so that if equality tests are desired, they can be timing invariant, without any chance that the further comparisons for greater than and less than can leak information. Maybe this is too paranoid, but I don't know how ruby works under the hood with comparable.

43
44
45
46
47
48
49
50
51
52
# File 'lib/rbnacl/key_comparator.rb', line 43

def ==(other)
  if KeyComparator > other.class
    other = other.to_bytes
  elsif other.respond_to?(:to_str)
    other = other.to_str
  else
    return false
  end
  Util.verify32(to_bytes, other)
end

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4