Atom

crypto.verify()

Compares byte sequences.

Signature

crypto.verify(first, second)

Parameters

Two text or packed values.

Returns

Boolean.

Behavior

Compares equal-length bytes in constant time. Different lengths return false immediately.

Errors

Invalid byte input.

Example

Atom
use crypto
a = crypto.hash('sha256', 'Atom')
assert(crypto.verify(a, copy(a)))

Compare two text values

Use verify when comparing a received authentication value with an expected one.

Atom
use crypto
print(crypto.verify('match', 'match'))
Output
true

The text values have the same bytes.

Compare packed bytes

A digest or tag is often already stored in binary form.

Atom
use binary
use crypto
first = binary.unhex('0102')
second = binary.unhex('0103')
print(crypto.verify(first, second))
Output
false

The two buffers differ in their last byte.