Module: Aliquot::Validator

Defined in:
lib/aliquot/validator.rb

Defined Under Namespace

Modules: InstanceMethods Classes: CommonPaymentMethodDetailsContract, ECv1_PaymentMethodDetailsContract, ECv1_TokenizedPaymentMethodDetailsContract, ECv2_PaymentMethodDetailsContract, ECv2_TokenizedPaymentMethodDetailsContract, EncryptedMessageContract, EncryptedMessageValidator, IntermediateSigningKeyContract, PaymentMethodDetailsValidator, SignedKeyContract, SignedKeyValidator, SignedMessage, SignedMessageContract, Token, TokenContract

Constant Summary collapse

CUSTOM_ERRORS =
{
  base64?:         'must be Base64',
  pan?:            'must be a PAN',
  ec_public_key?:  'must be an EC public key',
  eci?:            'must be an ECI',
  integer_string?: 'must be string encoded integer',
  month?:          'must be a month (1..12)',
  year?:           'must be a year (2000..3000)',
  base64_asn1?:    'must be base64-encoded ANS.1 value',
  json?:           'must be valid JSON',

  is_authMethodCryptogram3DS: 'authMethod CRYPTOGRAM_3DS or 3DS requires eciIndicator',
  is_authMethodCard:          'eciIndicator/cryptogram/3dsCryptogram must be omitted when PAN_ONLY',
}.freeze

Class Method Summary collapse

Class Method Details

.ans1_check(value) ⇒ Object



43
44
45
# File 'lib/aliquot/validator.rb', line 43

def self.ans1_check(value)
  OpenSSL::ASN1.decode(Base64.strict_decode64(value)) rescue false
end

.base64_check(value) ⇒ Object



28
29
30
31
32
33
# File 'lib/aliquot/validator.rb', line 28

def self.base64_check(value)
  /\A[=A-Za-z0-9+\/]*\z/.match?(value) && # allowable chars
    value.length.remainder(4).zero? && # multiple of 4
    !/=[^$=]/.match?(value) && # may only end with ='s
    !/===/.match?(value) # at most 2 ='s
end