ChecksumUtility

@objc public final class ChecksumUtility : NSObject

Utility for checksum generation and validation

  • Generate CRC16

    Parameter

    Parameter string: String to generate crc for

    Returns

    CRC16 in 4 digit hex code string format with 0 as padding

    Declaration

    Swift

    public static func crc16(string: String) -> String

    Parameters

    string

    String to generate crc for

    Return Value

    CRC16 in 4 digit hex code string format with 0 as padding

  • Checks if the qr string includes valid CRC16

    Parameter

    Parameter qrString: QR code string

    Returns

    true if the CRC16 in the qrString is valid else false

    Declaration

    Swift

    public static func isValidCrc16(qrString: String) -> Bool

    Parameters

    qrString

    QR code string

    Return Value

    true if the CRC16 in the qrString is valid else false

  • Valid luhn checksum of the string

    Parameter

    Parameter string: String to valid luhn checksum for

    Returns

    true if luhn checksum of the string is valid

    Precondition

    string should be numeric otherwise this method returns false

    Declaration

    Swift

    public static func validateLuhnChecksum(_ string: String) -> Bool

    Parameters

    string

    String to valid luhn checksum for

    Return Value

    true if luhn checksum of the string is valid

  • Generate luhn checksum of the string.

    Parameter

    Parameter string: String to valid luhn checksum for

    Returns

    Integer luhn checksum

    Throws

    MPQRError.invalidFormat if the the string is not numeric

    Precondition

    Check digit should not be present in the string

    Declaration

    Swift

    public static func luhnChecksum(_ string: String) throws -> NSNumber

    Parameters

    string

    String to valid luhn checksum for

    Return Value

    Integer luhn checksum

  • Generate luhn checksum of the string

    Parameter

    Parameter string: String to valid luhn checksum for

    Parameter

    Parameter hasCheckDigit: Whether Check digit is already present in the string or not.

    Returns

    Integer luhn checksum

    Throws

    MPQRError.invalidFormat if the the string is not numeric

    Declaration

    Swift

    public static func luhnChecksum(_ string: String, hasCheckDigit: Bool) throws -> NSNumber

    Parameters

    string

    String to valid luhn checksum for

    hasCheckDigit

    Whether Check digit is already present in the string or not.

    Return Value

    Integer luhn checksum