prevoty 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +38 -0
  6. data/Rakefile +8 -0
  7. data/lib/prevoty.rb +31 -0
  8. data/lib/prevoty/client.rb +341 -0
  9. data/lib/prevoty/crypto.rb +33 -0
  10. data/lib/prevoty/exceptions/account_quota_exceeded.rb +4 -0
  11. data/lib/prevoty/exceptions/bad_api_key.rb +4 -0
  12. data/lib/prevoty/exceptions/bad_input_parameter.rb +4 -0
  13. data/lib/prevoty/exceptions/internal_error.rb +4 -0
  14. data/lib/prevoty/hash.rb +12 -0
  15. data/lib/prevoty/pattern.rb +18 -0
  16. data/lib/prevoty/responses/api_key_info.rb +12 -0
  17. data/lib/prevoty/responses/decrypt_result.rb +9 -0
  18. data/lib/prevoty/responses/delete_token.rb +10 -0
  19. data/lib/prevoty/responses/ecdsa_private_key.rb +19 -0
  20. data/lib/prevoty/responses/ecdsa_public_key.rb +19 -0
  21. data/lib/prevoty/responses/ecdsa_signature.rb +17 -0
  22. data/lib/prevoty/responses/encrypt_result.rb +25 -0
  23. data/lib/prevoty/responses/filter_content.rb +11 -0
  24. data/lib/prevoty/responses/filter_statistics.rb +28 -0
  25. data/lib/prevoty/responses/generate_token.rb +10 -0
  26. data/lib/prevoty/responses/hash_result.rb +9 -0
  27. data/lib/prevoty/responses/input_validation.rb +10 -0
  28. data/lib/prevoty/responses/query_analysis.rb +87 -0
  29. data/lib/prevoty/responses/rsa_private_key.rb +22 -0
  30. data/lib/prevoty/responses/rsa_public_key.rb +17 -0
  31. data/lib/prevoty/responses/rsa_signature.rb +15 -0
  32. data/lib/prevoty/responses/signature_verify.rb +13 -0
  33. data/lib/prevoty/responses/validate_token.rb +10 -0
  34. data/lib/prevoty/version.rb +3 -0
  35. data/prevoty.gemspec +25 -0
  36. data/test/specs/client_spec.rb +563 -0
  37. data/test/test_helper.rb +10 -0
  38. metadata +124 -0
@@ -0,0 +1,33 @@
1
+ module Prevoty
2
+ module Crypto
3
+ module Algorithms
4
+ AES = 1
5
+ TriDES = 2
6
+ end
7
+
8
+ module Modes
9
+ CBC = 1
10
+ CFB = 2
11
+ CTR = 3
12
+ OFB = 4
13
+ end
14
+
15
+ module KeyAlgorithms
16
+ RSA_PKCS = 1
17
+ RSA_PSS = 2
18
+ ECDSA = 3
19
+ end
20
+
21
+ module Curves
22
+ P224 = 1
23
+ P256 = 2
24
+ P384 = 3
25
+ P521 = 4
26
+ end
27
+
28
+ module PSSSaltOptions
29
+ PSSSaltLengthAuto = 1
30
+ PSSSaltLengthEqualsHash = -1
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ module Prevoty
2
+ class AccountQuotaExceeded < Exception
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Prevoty
2
+ class BadAPIKey < Exception
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Prevoty
2
+ class BadInputParameter < Exception
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Prevoty
2
+ class InternalError < Exception
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ module Prevoty
2
+ module Hash
3
+ MD4 = 1
4
+ MD5 = 2
5
+ SHA1 = 3
6
+ SHA224 = 4
7
+ SHA256 = 5
8
+ SHA384 = 6
9
+ SHA512 = 7
10
+ RIPEMD160 = 8
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ module Prevoty
2
+ module Pattern
3
+ ALPHA = 'alpha'
4
+ ALPHANUMERIC = 'alphanumeric'
5
+ BASE64 = 'base64'
6
+ CREDITCARD = 'creditcard'
7
+ EMAIL = 'email'
8
+ IP = 'ip'
9
+ IPV6 = 'ipv6'
10
+ MAC = 'mac'
11
+ NUMERIC = 'numeric'
12
+ URL = 'url'
13
+ UUID = 'uuid'
14
+ UUID3 = 'uuid3'
15
+ UUID4 = 'uuid4'
16
+ UUID5 = 'uuid5'
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module Prevoty
2
+ class APIKeyInfo
3
+ attr_accessor :maximum, :used, :remaining, :message
4
+
5
+ def initialize(data)
6
+ @maximum = data["maximum"]
7
+ @used = data["used"]
8
+ @remaining = data["remaining"]
9
+ @message = data["message"]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Prevoty
2
+ class DecryptResult
3
+ attr_accessor :plain_text
4
+
5
+ def initialize(data)
6
+ @plain_text = data["plain_text"]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Prevoty
2
+ class DeleteToken
3
+ attr_accessor :deleted, :message
4
+
5
+ def initialize(data)
6
+ @deleted = data["deleted"]
7
+ @message = data["message"]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ module Prevoty
2
+ class ECDSAPrivateKey < ECDSAPublicKey
3
+ attr_accessor :d
4
+
5
+ def initialize(data)
6
+ super(data)
7
+ @d = data["d"]
8
+ end
9
+
10
+ def to_json(*a)
11
+ {
12
+ x: @x,
13
+ y: @y,
14
+ curve_id: @curve_id,
15
+ d: @d
16
+ }.to_json
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Prevoty
2
+ class ECDSAPublicKey
3
+ attr_accessor :x, :y, :curve_id
4
+
5
+ def initialize(data)
6
+ @x = data["x"]
7
+ @y = data["y"]
8
+ @curve_id = data["curve_id"]
9
+ end
10
+
11
+ def to_json(*a)
12
+ {
13
+ x: @x,
14
+ y: @y,
15
+ curve_id: @curve_id
16
+ }.to_json
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Prevoty
2
+ class ECDSASignature
3
+ attr_accessor :r, :s
4
+
5
+ def initialize(data)
6
+ @r = data["r"]
7
+ @s = data["s"]
8
+ end
9
+
10
+ def to_json(*a)
11
+ {
12
+ r: @r,
13
+ s: @s
14
+ }.to_json
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module Prevoty
2
+ class EncryptResult
3
+ attr_accessor :algorithm, :mode, :mac_key, :key, :mac, :cipher_text
4
+
5
+ def initialize(data)
6
+ @algorithm = data["algorithm"]
7
+ @mode = data["mode"]
8
+ @mac_key = data["mac_key"]
9
+ @key = data["key"]
10
+ @mac = data["mac"]
11
+ @cipher_text = data["cipher_text"]
12
+ end
13
+
14
+ def to_json(*a)
15
+ {
16
+ algorithm: @algorithm,
17
+ mode: @mode,
18
+ mac_key: @mac_key,
19
+ key: @key,
20
+ mac: @mac,
21
+ cipher_text: @cipher_text
22
+ }.to_json
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ module Prevoty
2
+ class FilterContent
3
+ attr_accessor :message, :output, :statistics
4
+
5
+ def initialize(data)
6
+ @message = data["message"]
7
+ @output = data["output"]
8
+ @statistics = FilterStatistics.new(data["statistics"])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module Prevoty
2
+ class FilterStatistics
3
+ attr_accessor :bytes,
4
+ :invalid_attributes, :invalid_protocols, :invalid_tags,
5
+ :blacklisted_phrases, :flagged_phrases,
6
+ :javascript_attributes, :javascript_protocols, :javascript_tags,
7
+ :prevoty_profanity_features, :prevoty_spam_features,
8
+ :prevoty_link_metadata, :prevoty_link_density,
9
+ :tags_balanced, :transformations
10
+ def initialize(data)
11
+ @bytes = data["bytes"]
12
+ @invalid_attributes = data["invalid_attributes"]
13
+ @invalid_protocols = data["invalid_protocols"]
14
+ @invalid_tags = data["invalid_tags"]
15
+ @blacklisted_phrases = data["blacklisted_phrases"]
16
+ @flagged_phrases = data["flagged_phrases"]
17
+ @javascript_attributes = data["javascript_attributes"]
18
+ @javascript_protocols = data["javascript_protocols"]
19
+ @javascript_tags = data["javascript_tags"]
20
+ @prevoty_profanity_features = data["prevoty_profanity_features"]
21
+ @prevoty_spam_features = data["prevoty_spam_features"]
22
+ @prevoty_link_metadata = data["prevoty_link_metadata"]
23
+ @prevoty_link_density = data["prevoty_link_density"]
24
+ @tags_balanced = data["tags_balanced"]
25
+ @transformations = data["transformations"]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ module Prevoty
2
+ class GenerateToken
3
+ attr_accessor :token, :message
4
+
5
+ def initialize(data)
6
+ @token = data["token"]
7
+ @message = data["message"]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Prevoty
2
+ class HashResult
3
+ attr_accessor :hash
4
+
5
+ def initialize(data)
6
+ @hash = data["hash"]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Prevoty
2
+ class InputValidation
3
+ attr_accessor :matched, :message
4
+
5
+ def initialize(data)
6
+ @matched = data["matched"]
7
+ @message = data["message"]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,87 @@
1
+ module Prevoty
2
+ class QueryAnalysis
3
+ attr_accessor :version, :processed, :compliant, :statements, :error
4
+
5
+ def initialize(data)
6
+ @version = data["version"]
7
+ @processed = data["processed"]
8
+ @compliant = data["compliant"]
9
+ @statements = data["statements"].map {|statement| Statement.new(statement)}
10
+ @error = data["error"]
11
+ end
12
+ end
13
+
14
+ class Statement
15
+ attr_accessor :intelligence, :violations
16
+
17
+ def initialize(data)
18
+ @intelligence = Intelligence.new(data["intelligence"])
19
+ @violations = Violations.new(data["violations"])
20
+ end
21
+ end
22
+
23
+ class Intelligence
24
+ attr_accessor :statement_type, :row_creates, :column_reads, :column_updates,
25
+ :row_deletes, :has_admin, :function_calls, :joins, :unions,
26
+ :subqueries
27
+
28
+ def initialize(data)
29
+ @statement_type = data["statement_type"]
30
+ @row_creates = data["row_creates"].map {|el| Table.new(el)}
31
+ @column_reads = data["column_reads"].map {|el| Column.new(el)}
32
+ @column_updates = data["column_updates"].map {|el| Column.new(el)}
33
+ @row_deletes = data["row_deletes"].map {|el| Table.new(el)}
34
+ @has_admin = data["has_admin"]
35
+ @function_calls = data["function_calls"].map {|el| FunctionCall.new(el)}
36
+ @joins = data["joins"].map {|el| Table.new(el)}
37
+ @unions = data["unions"].map {|el| Table.new(el)}
38
+ @subqueries = data["subqueries"].map {|el| Table.new(el)}
39
+ end
40
+ end
41
+
42
+ class Table
43
+ attr_accessor :database, :table
44
+
45
+ def initialize(data)
46
+ @database = data["database"]
47
+ @table = data["table"]
48
+ end
49
+ end
50
+
51
+ class Column
52
+ attr_accessor :database, :table, :column
53
+
54
+ def initialize(data)
55
+ @database = data["database"]
56
+ @table = data["table"]
57
+ @column = data["column"]
58
+ end
59
+ end
60
+
61
+ class FunctionCall
62
+ attr_accessor :name, :arguments
63
+
64
+ def initialize(data)
65
+ @name = data["name"]
66
+ @arguments = data["arguments"]
67
+ end
68
+ end
69
+
70
+ class Violations
71
+ attr_accessor :row_create_violations, :column_read_violations, :column_update_violations,
72
+ :row_delete_violation, :admin_violation, :union_violations, :join_violations,
73
+ :subquery_violations, :function_violations
74
+
75
+ def initialize(data)
76
+ row_create_violations = data["row_create_violations"].map {|el| Table.new(el)}
77
+ column_read_violations = data["column_read_violations"].map {|el| Column.new(el)}
78
+ column_update_violations = data["column_update_violations"].map {|el| Column.new(el)}
79
+ row_delete_violations = data["row_delete_violations"].map {|el| Table.new(el)}
80
+ admin_violation = data["admin_violation"]
81
+ union_violations = data["union_violations"].map {|el| Table.new(el)}
82
+ join_violations = data["join_violations"].map {|el| Table.new(el)}
83
+ subquery_violations = data["subquery_violations"].map {|el| Table.new(el)}
84
+ function_violations = data["function_violations"].map {|el| FunctionCall.new(el)}
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,22 @@
1
+ module Prevoty
2
+ class RSAPrivateKey < RSAPublicKey
3
+ attr_accessor :d, :primes, :precomputed
4
+
5
+ def initialize(data)
6
+ super(data)
7
+ @d = data["D"]
8
+ @primes = data["Primes"]
9
+ @precomputed = data["Precomputed"]
10
+ end
11
+
12
+ def to_json(*a)
13
+ {
14
+ E: @e,
15
+ N: @n,
16
+ D: @d,
17
+ Primes: @primes,
18
+ Precomputed: @precomputed
19
+ }.to_json
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ module Prevoty
2
+ class RSAPublicKey
3
+ attr_accessor :n, :e
4
+
5
+ def initialize(data)
6
+ @n = data["N"]
7
+ @e = data["E"]
8
+ end
9
+
10
+ def to_json(*a)
11
+ {
12
+ N: @n,
13
+ E: @e
14
+ }.to_json
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module Prevoty
2
+ class RSASignature
3
+ attr_accessor :signature
4
+
5
+ def initialize(data)
6
+ @signature = data["signature"]
7
+ end
8
+
9
+ def to_json(*a)
10
+ {
11
+ signature: @signature
12
+ }.to_json
13
+ end
14
+ end
15
+ end