Class: CertificateFingerprintValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- CertificateFingerprintValidator
- Defined in:
- app/validators/certificate_fingerprint_validator.rb
Constant Summary collapse
- FINGERPRINT_PATTERN =
/\A([a-zA-Z0-9]{2}[\s\-:]?){16,}\z/
- SHA1_FINGERPRINT_PATTERN =
/\A(?:(?:[A-Fa-f0-9]{2}[\s:]){19}[A-Fa-f0-9]{2}|[A-Fa-f0-9]{40})\z/
- SHA256_FINGERPRINT_PATTERN =
/\A(?:(?:[A-Fa-f0-9]{2}[\s:]){31}[A-Fa-f0-9]{2}|[A-Fa-f0-9]{64})\z/
- MIN_LENGTH =
40
- MAX_LENGTH =
95
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'app/validators/certificate_fingerprint_validator.rb', line 10 def validate_each(record, attribute, value) # We introduce the new validation logic only for new records and updates that will change the attribute # in order to limit the impact on existing invalid records. if record.new_record? || record.will_save_change_to_attribute?(attribute) validate_sha1_or_sha256_pattern(record, attribute, value) else validate_length_and_pattern(record, attribute, value) end end |