ig-validator-utils 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ig-validator-utils.rb +64 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a129046a5e9e0dc6ee112016ef1de09090c998d3
|
4
|
+
data.tar.gz: d5b05aac029ef7d1f7625259398aeed8c405f834
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c331e0c49cd728b716da7af232da083376ac3afc3783a27b0da5d92e6057cc5baef6adfa4353e72c34c7991ff9811791c4c05116723bceb85b062123ebf25ad9
|
7
|
+
data.tar.gz: 4c339adc9d856b60b1df498281fa63f307e44e3ed444e0266384d3faf6235c67b6b2fbb44e66c8be48e8ce7ba12eaa363a6ffe458816d421869d32f8dc18933d
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module ValidatorUtils
|
2
|
+
class GeneralValidator
|
3
|
+
def self.validate_string(value)
|
4
|
+
value.to_s != ''
|
5
|
+
end
|
6
|
+
|
7
|
+
# \p{L} matches a single unicode letter
|
8
|
+
# also allows '.', '-', '_', '@'
|
9
|
+
# takes into account usernames that are email addresses
|
10
|
+
def self.validate_username_strict(value)
|
11
|
+
value =~ /^[\p{L} .-@_]+$/i
|
12
|
+
end
|
13
|
+
|
14
|
+
# \p{L} matches a single unicode letter
|
15
|
+
# also allows points, apostrophe and hyphen
|
16
|
+
def self.validate_string_strict(value)
|
17
|
+
value =~ /^[\p{L} .'-]+$/i
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.validate_integer(value)
|
21
|
+
Float(value) != nil rescue false
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.validate_uuid(value)
|
25
|
+
value =~ /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.validate_hex(value)
|
29
|
+
value =~ /^[a-f\d]{24}$/i
|
30
|
+
end
|
31
|
+
|
32
|
+
# At least one upper case letter
|
33
|
+
# At least one lower case letter
|
34
|
+
# At least one digit
|
35
|
+
# Minimum 6 in length
|
36
|
+
# Maximum 12 in length
|
37
|
+
def self.validate_password(value)
|
38
|
+
value =~ /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{6,12}$/
|
39
|
+
end
|
40
|
+
|
41
|
+
# for a 256-bit ECDSA curve, the uncompressed pubkey is 512 bits (256 bits of x, 256 bits of y, no sign bit).
|
42
|
+
# the compressed pubkey is 257 bits (256 bits of x, one bit of the sign of y).
|
43
|
+
# this equates to 32 bytes (ie: 256/8 = 32) + 1 (the sign) = 33
|
44
|
+
def self.validate_public_ecdsa_key(value)
|
45
|
+
decoded_key = Base64.decode64 value
|
46
|
+
decoded_key.length == 33
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.validate_unix_datetime(value)
|
50
|
+
begin
|
51
|
+
now = Date.today.to_time
|
52
|
+
time_to_validate = Time.at value
|
53
|
+
return time_to_validate > now
|
54
|
+
rescue
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# validates base64 encoding (includes newline constants '\n')
|
60
|
+
def self.validate_base_64(value)
|
61
|
+
value =~ /^[A-Za-z0-9+\/=\\]+={0,3}$/
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ig-validator-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Infinity-G
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: General validator for request data
|
14
|
+
email: developer@infinity-g.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ig-validator-utils.rb
|
20
|
+
homepage: ''
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.5
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: General field validator
|
44
|
+
test_files: []
|