[][src]Function validbr::cnpj::calculate_verifier_digit

pub fn calculate_verifier_digit<const S: usize>(cnpj_digits: [u8; S]) -> u8

Calculates the verifier digit given input [cnpj_digits].

This function does not care about the amount of digits provided to it, but the correct amount of digits to be provided to this function is either 12 CNPJ digits with branch digits or 13 values (12 CNPJ digits with branch digits and first verifier digit). When provided with 12 CPF digits, the function calculates the first verifier digits, when provided with 13 values (12 CNPJ digits and first verifier digit), the function calculates the second verifier digits.

Example

use validbr::cnpj::calculate_verifier_digit;
use validbr::cnpj::DigitCalculationError::WrongAmountOfDigits;

assert_eq!(calculate_verifier_digit([5, 3, 8, 7, 1, 1, 4, 3, 0, 0, 0, 1]), 3);
assert_eq!(calculate_verifier_digit([5, 3, 8, 7, 1, 1, 4, 3, 0, 0, 0, 1, 3]), 5);

assert_eq!(calculate_verifier_digit([3, 4, 8, 5, 4, 6, 7, 8, 0, 0, 0, 1]), 5);
assert_eq!(calculate_verifier_digit([3, 4, 8, 5, 4, 6, 7, 8, 0, 0, 0, 1, 5]), 3);

assert_eq!(calculate_verifier_digit([3, 1, 2, 3, 8, 8, 2, 6, 0, 0, 0, 1]), 1);
assert_eq!(calculate_verifier_digit([3, 1, 2, 3, 8, 8, 2, 6, 0, 0, 0, 1, 1]), 7);