class SmartId::Utils::VerificationCodeCalculator
Public Class Methods
calculate(digest)
click to toggle source
The Verification Code (VC) is computed as:
integer(SHA256(hash)) mod 10000
where we take SHA256 result, extract 2 rightmost bytes from it, interpret them as a big-endian unsigned short and take the last 4 digits in decimal for display.
SHA256 is always used here, no matter what was the algorithm used to calculate hash.
# File lib/smart_id/utils/verification_code_calculator.rb, line 14 def self.calculate(digest) rightmost_bytes = digest[-2..-1] int = rightmost_bytes.unpack('n*')[0] paddable_string = (int % 10000).to_s.chars.last(4).join pad = 4 - paddable_string.length "0" * pad + paddable_string end